XSLT2.0 in XMLTransform?

I’m trying to move from CF10 to Lucee and find a way to get XMLTransform to work with some long running XSLT2.0.

I see that saxon he is not be default installed with Lucee (Lucee 5.2.1.9) so I found the OSGi at


and placed it in …/tomcat/lucee-server/bundles/. I now see Saxon in the admin page ‘info.bundle’ shown as ‘not loaded’.

And the stacktrace is still showing xalan.
lucee.runtime.exp.NativeException: javax.xml.transform.TransformerException: org.xml.sax.SAXException: Could not find function: format-date javax.xml.transform.TransformerException: Could not find function: format-date at lucee.runtime.exp.NativeException.newInstance(NativeException.java:73) at lucee.runtime.op.Caster.toPageException(Caster.java:3201) at lucee.runtime.op.Caster.toPageException(Caster.java:3176) at lucee.runtime.functions.xml.XmlTransform.call(XmlTransform.java:54) at lucee.runtime.functions.xml.XmlTransform.call(XmlTransform.java:39) at xsl_body_cfm$cf.call(/xsl_body.cfm:55) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:897) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:842) at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:63) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2408) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2398) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2366) at lucee.runtime.engine.Request.run(Request.java:34) Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXException: Could not find function: format-date javax.xml.transform.TransformerException: Could not find function: format-date at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:925) at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:771) at lucee.runtime.text.xml.XMLUtil.transform(XMLUtil.java:1048) at lucee.runtime.functions.xml.XmlTransform.call(XmlTransform.java:51) ... 10 more Caused by: org.xml.sax.SAXException: Could not find function: format-date javax.xml.transform.TransformerException: Could not find function: format-date at org.apache.xalan.processor.XSLTAttributeDef.processAVT(XSLTAttributeDef.java:526) at org.apache.xalan.processor.XSLTAttributeDef.processValue(XSLTAttributeDef.java:1393) at org.apache.xalan.processor.XSLTAttributeDef.setAttrValue(XSLTAttributeDef.java:1601) at org.apache.xalan.processor.XSLTElementProcessor.setPropertiesFromAttributes(XSLTElementProcessor.java:355) at org.apache.xalan.processor.XSLTElementProcessor.setPropertiesFromAttributes(XSLTElementProcessor.java:267) at org.apache.xalan.processor.ProcessorLRE.startElement(ProcessorLRE.java:283) at org.apache.xalan.processor.StylesheetHandler.startElement(StylesheetHandler.java:623) at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1276) at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:324) at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:291) at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:207) at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:917) ... 13 more Caused by: javax.xml.transform.TransformerException: Could not find function: format-date at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:610) at org.apache.xpath.compiler.XPathParser.FunctionCall(XPathParser.java:1507) at org.apache.xpath.compiler.XPathParser.PrimaryExpr(XPathParser.java:1446) at org.apache.xpath.compiler.XPathParser.FilterExpr(XPathParser.java:1345) at org.apache.xpath.compiler.XPathParser.PathExpr(XPathParser.java:1278) at org.apache.xpath.compiler.XPathParser.UnionExpr(XPathParser.java:1236) at org.apache.xpath.compiler.XPathParser.UnaryExpr(XPathParser.java:1142) at org.apache.xpath.compiler.XPathParser.MultiplicativeExpr(XPathParser.java:1063) at org.apache.xpath.compiler.XPathParser.AdditiveExpr(XPathParser.java:1005) at org.apache.xpath.compiler.XPathParser.RelationalExpr(XPathParser.java:930) at org.apache.xpath.compiler.XPathParser.EqualityExpr(XPathParser.java:870) at org.apache.xpath.compiler.XPathParser.AndExpr(XPathParser.java:834) at org.apache.xpath.compiler.XPathParser.OrExpr(XPathParser.java:807) at org.apache.xpath.compiler.XPathParser.Expr(XPathParser.java:790) at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:129) at org.apache.xpath.XPath.<init>(XPath.java:227) at org.apache.xalan.processor.StylesheetHandler.createXPath(StylesheetHandler.java:152) at org.apache.xalan.templates.AVT.<init>(AVT.java:308) at org.apache.xalan.processor.XSLTAttributeDef.processAVT(XSLTAttributeDef.java:520) ... 24 more

Is there a way for me to get XMLTransform function to use Saxon? Or am I barking up the wrong tree?

I’ve tried setting the TransformerFactory in the JVM config . . .
No love :frowning:

I’ve tried adding the JVM config to setenv.sh

CATALINA_OPTS="-Xms256m -Xmx512m -Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl";

Still no joy :frowning:

I’m not sure I know enough about java but it looks to me like the

import org.apache.xalan.processor.TransformerFactoryImpl;

found here:


should be removed letting the previous

import javax.xml.transform.TransformerFactory;

select the factory set in config files (the first one found or one specified in various config methods shown here:
http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=3#plug_layer

Unfortunately, I’m not much of a java coder so I’m not in a position to pull the XMLUtil.java; adjust it; compile it; and test it. But I still believe that the issue outlined above is the source of my difficulties. Instead I’ve simply re-written the native function to instantiate the saxon stuff inside the cfml environment I’m accustomed to. It’s moving me forward on transferring from CF10 to Lucee. I may revisit this issue when I have more time (teach myself some java).

Here’s what I’ve done - far from perfect and it’ll evolve as I go forward I’m sure - but it’s working at the moment:

public string function XMLTransform (xmlDoc, xslDoc) {
        try {   
                if (IsXmlNode(arguments.xmlDoc)) {
                        arguments.xmlDoc = arguments.xmlDoc.toString();
                }
                if (IsXmlNode(arguments.xslDoc)) {
                        arguments.xslDoc = arguments.xslDoc.toString();
                }
                if (FileExists(arguments.xslDoc)) {
                        arguments.xslDoc = FileRead(arguments.xslDoc);
                }
                xslReader = createObject('java','java.io.StringReader').init(arguments.xslDoc);
                xmlReader = createObject('java','java.io.StringReader').init(arguments.xmlDoc);
                stmXSL = createObject('java','javax.xml.transform.stream.StreamSource').init(xslReader);
                stmXML = createObject('java','javax.xml.transform.stream.StreamSource').init(xmlReader);
                proc = createObject('java','net.sf.saxon.s9api.Processor','org.apache.servicemix.bundles.saxon').init(false);
                dest = createObject('java','net.sf.saxon.s9api.XdmDestination').init();

                comp = proc.newXsltCompiler();
                exec = comp.compile(stmXSL);
                transformer = exec.load();
                transformer.setDestination(dest);

                builder = proc.newDocumentBuilder();
                builder.setLineNumbering(true);
                source = builder.build(stmXML);

                transformer.setInitialContextNode(source);
                
                transformer.transform();
        } catch (any e) {
                if (structKeyExists(request, 'stcErr')) {
                        request.stcErr.transArgs = arguments;
                        request.stcErr.catch = e;
                }
        }

        return dest.getXdmNode().toString();
}

Worth noting the saxon-he OSGi bundle posted above did NOT work even when working directly with the objects themselves. I’m not recalling what stopped me there. Instead I pulled from here:

https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.saxon

1 Like