Jump to content

XSLT and java issue


markh

This topic is 6553 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi, i have a problem. I've just started using the XSLT availablity from filemaker and now i would like to use some javascript inside my xslt. As filemaker, xml, xslt is not my background this is causing me some frusticleastion. Problem is, it don't work for toffee. I've tried some of the online exmaples etc. But have had no luck. I can get it to work if i use ONE javascript function. But when i need to pass one value into another function nothing happens. I have >< symbols in it also and can not get nothing to work. I am now fed-up. Can anyone provide a short or long example of what is the best approach to using javascript inside my XSLT that uses more than one function and escape all the characters the xslt does not like. This would be most greatfull. I will buy you a beer also. Cheers

Edited by Guest
Link to comment
Share on other sites

Hi Martin,

Snippet of code as follows:

This is the javascript section

var endDate = "05/9/2006"

i = 0;

function calcJulian(isDate){

gregDate = new Date(isDate);

year = gregDate.getFullYear();

month = gregDate.getMonth()+1;

day = gregDate.getDate();

nDay[i++] = gregDate.getDay();

A = Math.floor((7*(year+Math.floor((month+9)/12)))/4);

B = day+Math.floor((275*month)/9);

isJulian = (367*year)-A+B+1721014;

return isJulian

}

function countDays(isBase) {

isValid = true;

isToday = (isBase);

currDate = calcJulian(endDate);

baseDate = calcJulian(isToday);

daysApart = currDate-baseDate;

if (daysApart< 0) {isValid = false}

if (nDay[1] == 0 || nDay[1] == 6){isValid = false}

if (isValid)

{

workDays = daysApart-(parseInt(daysApart/7)*2);

if (nDay[0] < nDay[1]){workDays = workDays-2}

}

if (!isValid){alert('Invalid Start Date')}

}

This is the section when i call the javascript:

Edited by Guest
Link to comment
Share on other sites

PS.

I've been having a few issues posting the above snippet but it looks ok now. I'd forgot to mention. I'd been trying to escape the <> characters etc. But with no luck. So i've pasted the raw javacript code i am trying to get to work. Basically its a routine to work out the number of days between to date values, that omits the weekends. And only counts the number of working days in the week. I could not seem to find any xslt routine that could do that for me, so thats why i turned to javascript.

Thanks again.

Link to comment
Share on other sites

What data type is $_field-nameSD, a date or a number?

If it is a date, then you may use the following:

....

Next, in your JavaScript function, there is some strange behaviour depending on the browser:

You initialize i=0; (BTW, rather use var i=0; IE does not seem to like if JavaScript variables are introduced without var declaration).

Later, you set

nDay[i++] = gregDate.getDay();

FireFox interprets that correctly, with nDay[0] = day after first function call and nDay[1] = day after second function call

Safari has nDay[0] = undefined, nDay[1] = day after second function call (seems to be a bug of Safari).

BTW: You can debug your JavaScript with the JavaScript console in Firefox or in Safari. With IE you need to download the Script debugger from Microsoft: http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

Link to comment
Share on other sites

Wow,

Thanks for that Martin, It's amazing when you have a fresh pair of eyes on the job. Sorry for my sloppy javascript code. Also thanks for the XSLT option i'll give that a go also.

Many Thanks

Link to comment
Share on other sites

Hi

I've now got the javascript working within my xslt, but i need your advice again. It appears i now have a problem calling this function. It works if i use the onclick command to call it. But i just want it to get called as the xslt code literates thourgh the records. Just like countdays(date1,date2) rather than the onclick="countdays(date1,date2). Sorry to be a pain, any idea?

Edited by Guest
Link to comment
Share on other sites

Within the

tags of your HTML, add

window.onload=function() {

countdays(date1,date2);

}

Or if the dates are dynamic use xsl:value-of instead of xsl:text and of course the concat() function.

The JavaScript will still be executed browser-side.

Another way is to extend your XSLT according to p. 76 of the FMSA CWP Guide for server-side execution of the script.

Link to comment
Share on other sites

This topic is 6553 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.