Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XSLT and java issue

Featured Replies

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

Can you post some code? The problems mostly are connected with the use of apostrophes.

  • Author

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

  • Author

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.

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

Another mistake: nDay is only defined locally within function calcJulian. The function countDays knows nothing about the declaration of nDay.

And that would be a solution in XSLT:




  

  

    

    

    

    

    

    

      

        

      

    

    

    

      

        

      

    

    

    

    

    

    

    

    

      

        
Invalid Start Date!

      

      

        

          

            
Invalid Start Date!

          

          

            

            

              

                

              

              

                

              

            

          

        

        

      

    

   

   

   

     

     

     

     

     

     

     

   



  • Author

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

  • Author

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

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.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.