How to call java method from an Xsl stylesheet
Xalan is the default processor of the JDK. It implements XSL Transformations (XSLT) Version 1.0
XSLT is not an object oriented language. Static methods fit much more neatly into its structures than do objects and instance methods.
<xsl:value-of select="myPrefix:getMyStaticMethod(number(myNodeName))" xmlns:myPrefix="xalan://myPackage.myClass"/>
To create an instance of an object:
prefix:new (args)
where prefix is the extension namespace prefix.
A new instance is to be created with the args constructor arguments (if any). All constructor methods are qualified for method selection. Example:
<xsl:variable name="myType" select="my-class:new()">
To invoke an instance method on a specified object:
prefix:methodName (object, args)
where:
Example:
<xsl:variable name="new-pop" select="my-class:valueOf($myType, string(@myAttribute))">
ERROR: 'The first argument to the non-static Java function 'getWorkHierarchyType' is not a valid object reference.'
FATAL ERROR: 'The first argument to the non-static Java function 'getWorkHierarchyType' is not a valid object reference.'
Just verify that the path that refers to the static method is the good one.
WARNING: 'org.apache.xerces.jaxp.SAXParserImpl: http://javax.xml.XMLConstants/property/accessExternalDTD'
ERROR: 'Cannot convert argument/return type in call to method 'myPackage.myClass.getMyStatiscMethod(node-set)''
FATAL ERROR: 'Cannot convert argument/return type in call to method 'myPackage.myClass.getMyStatiscMethod(node-set)''
Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Cannot convert argument/return type in call to method 'myPackage.myClass.getMyStatiscMethod(node-set)'
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:994)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:766)
It seems that the return value has a node-set datatype. By applying a conversion function, the problem was resolved.
See http://xml.apache.org/xalan-j/extensions.html