I am trying to run a XSLT 2.0 transformation from a XML file on a Tomcat v8.0 Server. However, I only succeed in running it as XSLT1.
Anytime I try to use a XSLT2 function, I get such an error:
org.apache.xml.utils.WrappedRuntimeException: java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xml.utils.NodeVector.root([ExpressionContext,] ).
I am using Saxon, here is the pom declaration:
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>10.0</version>
</dependency>
The library Saxon-HE-10.0.jar is indeed loaded when I build the project.
My java method goes (for the sake of this try, inputFile sends any well-formed xml file):
public File transfoTest(InputStream inputFile) throws Exception {
logger.debug("Begin transformation test");
File output = File.createTempFile("output", ".xml");
output.deleteOnExit();
InputStream xslFile = getClass().getResourceAsStream("/xslTransformerFiles/transfoXSLT.xsl");
OutputStream osOutputFile = FileUtils.openOutputStream(output);
PrintStream printStream = new PrintStream(osOutputFile);
StreamSource xsrc = new StreamSource(xslFile);
TransformerFactory transformerFactory = net.sf.saxon.TransformerFactoryImpl.newInstance();
Transformer xsltTransformer = transformerFactory.newTransformer(xsrc);
xsltTransformer.transform(new StreamSource(inputFile), new StreamResult(printStream));
inputFile.close();
xslFile.close();
osOutputFile.close();
printStream.close();
logger.debug("End transformation test");
return output;
}
Here is transfoXSLT.xsl:
<?xml version="1.1" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:value-of select="'xsl:version: '" />
<xsl:value-of select="system-property('xsl:version')" />
</xsl:template>
</xsl:stylesheet>
And here is the disappointing output:
<?xml version="1.0" encoding="UTF-8"?>
xsl:version: 1