I'm trying to call from XSLT a static java code. My XSLT file looks as the following
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="interface.dev"
exclude-result-prefixes="ns1"
xmlns:xltxe="http://www.ibm.com/xmlns/prod/xltxe-j"
xmlns:countryCode="http://com.abc/common/utils">
<xltxe:java-extension prefix="countryCode" class="com.abc.common.utils.CountryStaticInfo"/>
<xsl:variable name="var" select="ns1:parties/ns1:party[@code='BNE']/ns1:country"/>
<xsl:template match="/ns1:import_lc_iss">
<html>
<body>
<table border="1">
<tr>
<xsl:value-of select="countryCode:getCountryCode($var)" />
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
My Java code looks like that:
public synchronized static String getCountryCode(String aS_ctryCode) throws Exception, StaticInfoException {
ArrayList lAL_entities = com.abc.services.JavaProgramContext.getServerEntities();
return getCountryCode(lAL_entities.get(0).toString(),aS_ctryCode);
}
I get the following error
RROR: 'The first argument to the non-static Java function 'getCountryCode' is not a valid object reference.
46860 [main] ERROR - Cannot transform the recieved message via xslt javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:828) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:617)
1st amendment: the new xslt with xalan support
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="interface.dev"
exclude-result-prefixes="ns1"
xmlns:xalan="http://xml.apache.org/xalan"
extension-element-prefixes="xalan"
xmlns:java="java"
xmlns:util="com.abc.common.utils.CountryStaticInfo">
<xltxe:java-extension prefix="countryCode" class="com.abc.common.utils.CountryStaticInfo"/>
<xsl:variable name="var" select="AU"/>
<xsl:template match="/ns1:import_lc_iss">
<html>
<body>
<table border="1">
<tr>
<xsl:variable name="new-pop" select="com.abc.common.utils.CountryStaticInfo.getCountryCode(string(@var))"/>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Here is an example following the documentation and examples in http://xml.apache.org/xalan-j/extensions.html#ext-functions that works fine for me with Oracle JRE 8, the XSLT is
the Java class library has in the package
org.example
hasand then the built-in
Transformer
in the JRE transforms this example fine.