Search code examples
c#xmlxsltoxygenxml

ERR XTDE1425 while using Saxon - EE 11.4 On xml editor <Oxygen>


I have the following lines of XSLT. When i try to transform my xml doc I receive the following:

Cannot find a 1-argument function named Q{urn:js}RoundOff()

I believe that there is no issue with the actual script just something that I need to change in the parser setting but I am not sure what to or where to change these settings.

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:js="urn:js"
 exclude-result-prefixes="msxsl js">
 
 <msxsl:script language="JavaScript" implements-prefix="js">
  <![CDATA[
        function roundOff(hours) {
            return Math.round(hours * 100) / 100;
        }

        function getPeriodEndDate() {
            var today = new Date();
            var dayOfWeek = today.getDay();

            var tdate = new Date(today.getFullYear(), today.getMonth(), today.getDate());

            if (dayOfWeek === 0) {
                tdate.setDate(tdate.getDate() - 1);
            } else if (dayOfWeek === 1) {
                tdate.setDate(tdate.getDate() - 2);
            } else if (dayOfWeek === 2) {
                tdate.setDate(tdate.getDate() - 3);
            } else if (dayOfWeek === 3) {
                tdate.setDate(tdate.getDate() - 4);
            } else if (dayOfWeek === 4) {
                tdate.setDate(tdate.getDate() - 5);
            } else if (dayOfWeek === 5) {
                tdate.setDate(tdate.getDate() - 6);
            }

            var year = tdate.getFullYear();
            var month = tdate.getMonth() + 1;
            var day = tdate.getDate();

 

            if (month < 10) {
                month = '0' + month;
            }

            if (day < 10) {
                day = '0' + day;
            }

            return year + month + day;
        }
        ]]>
 </msxsl:script>```

....
<Additional lines of xsl>
....


<xsl:value-of select="js:RoundOff(SickHoursAccrued + SickHoursUsed)"  />



Assistance in editing or changing settings to allow the xslt to parse without errors 

Solution

  • Basically, you seem to expect to be able to implement extension functions for XSLT with J(ava)Script, that is not something that Saxon supports.

    XSLT 2 and 3, and Saxon 11 is an XSLT 3 processor, have a rich XPath function library shared with XPath and XQuery, and furthermore allow you to declare and implement your own functions in pure XSLT/XPath.

    So first check whether any of the functionality you need is available in https://www.w3.org/TR/xpath-functions-31/ (e.g. https://www.w3.org/TR/xpath-functions-31/#func-round), if not, implement it in XSLT/XPath using xsl:function: https://www.w3.org/TR/xslt-30/#stylesheet-functions