0

how to use java in xslt and avoid below errors:

Cannot find a 1-argument function named {java:com.poc.XSDDateTimeFormatter}toXSD(). Reflexive calls to Java methods are not available under Saxon-HE and Cannot find a 2-argument function named {urn:java:com.poc.NLDataUnitTestTimeCalc}computeTestTime(). Reflexive calls to Java methods are not available under Saxon-HE

computeTestTime method of NLDataUnitTestTimeCalc class

public static long computeTestTime( String startDateStr, String endDateStr) {

  long testTime= 0;
  long longStartDate= 0;
  long longEndDate= 0; 

  for( String format: formats) {
     try {
        SimpleDateFormat formatter = new SimpleDateFormat(format);

        Date startdate = formatter.parse(startDateStr);
        Date enddate = formatter.parse(endDateStr);
        longStartDate=startdate.getTime();
        longEndDate=enddate.getTime();
        testTime = (Math.abs(longEndDate-longStartDate)/1000);
        break; 
     }
     catch (ParseException ex) {
        //ignore
     }
  }
  return testTime; 

}

toXSD method of XSDDateTimeFormatter class

public static String toXSD( String dateStr) {
  for( String format: formats) {
     try {
        Date date = new SimpleDateFormat( format).parse( dateStr);
        String xsd = new SimpleDateFormat( XSDdateTimeFormat).format( date);

        //special case for xsd:dateTime timezone format
        return 
                xsd.substring(0, xsd.length() - 2) + 
                ':' +
                xsd.substring(xsd.length() - 2);
     } catch (ParseException ex) {
        //ignore
     }
  }

  return dateStr;   }

xslt

<xsl:template match="/Event">

        <bus:Timestamp> 
          <xsl:value-of                   xmlns:XSDDateTimeFormatter="java:com.amd.pde.integration.XSDDateTimeFormatter"
              select="XSDDateTimeFormatter:toXSD( //TimeStamp)"
           />   
        </bus:Timestamp>

sample xml

<Event>   
<Message>BEGINEXECUTION</Message>
<TimeStamp>20080111000419146</TimeStamp>
<EquipmentID>stack</EquipmentID>
</Event>
1
  • let me know how to resolve the issue Working example for the same will be better Commented Mar 26, 2018 at 14:52

1 Answer 1

3

As the error message says, you use Saxon-HE, but extension functions in Java are only supported by Saxon-PE and Saxon-EE. The Saxon-Docs mention this explicitly.

I guess you have two options

  • Buy Saxon-PE or Saxon-EE
  • Implement your functions in XSL
Sign up to request clarification or add additional context in comments.

8 Comments

I did not find any dependency either for Saxon-PE or Saxon-EE.
Yes, that is the problem. You don't have Saxon-PE or Saxon-EE available, but Saxon-HE (the free edition). But the free edition cannot call Java functions from XSL. For this you need one of the two paid editions. This is what Saxon says in the error message.
There are three options I think, the third being that you can write the extension function code as integrated extension functions saxonica.com/html/documentation/extensibility/… and that way can make use of Java.
I wonder if the XSDDateTimeFormatter is really doing anything that can't be done using the standard format-dateTime() function in XSLT 2.0/3.0?
That sounds like if ($x castable as xs:dateTime) then format-dateTime(xs:dateTime($x)) else $x.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.