Search code examples
javac++xsltsaxonsaxon-c

Saxon/C HE 11.2 prints empty output when XSLT has an include or using "xsl::result-document"


When i change the xsl:include to xsl:import it somehow works and doesnt return an empty file. I am using the Xslt30Processor class and function Xslt30Processor::TransformFiletoFile(), even The transform.c doesnt work. When my xslt has a "xsl:result-document" statement it also doesnt work.

I even tried using a previous version of Saxon/C (The 1.2.0 series) , and even that didnt work. Is there any option where it enables the use of xsl:include or something.

This works for Java and .NET but not for the C API. I don't get any errors or exceptions when using JNI. Please help.

Here a small example which demostrates the problem:

source.xml:

<xml/>

main.xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text" encoding="utf-8" standalone="yes"/>
  <xsl:include href="referenced.xsl" />

  <xsl:template match="/">hello</xsl:template>
</xsl:stylesheet>

referenced.xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:f="my-functions.org"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                version="2.0">
  <xsl:function name="f:next-nr" as="xs:integer">
    <xsl:param name="node"/>
    <xsl:sequence select="xs:integer(replace($node, '\D', ''))"/>
  </xsl:function>
</xsl:stylesheet>

When running the C version of Transform.exe, no errors are returned and no output is produced. I noticed when putting together this test case that it doesn't matter if I change the include to import for this example. If I use the Transform.exe that comes in the tools folder of Saxon 10.6, a file is produced as expected. I can't, however, find any C/C++ files for Saxon 10.6.

The issue with result-document is a separate issue with the same outcome.


Solution

  • I think I have found one reason why the stylesheet fails on compilation, it seems a build/configuration problem with HE not finding categories.xml.

    Stack trace from compilation:

    Exception in thread "main" java.lang.ExceptionInInitializerError
            at net.sf.saxon.regex.RECompiler.escape(Unknown Source)
            at net.sf.saxon.regex.RECompiler.parseTerminal(Unknown Source)
            at net.sf.saxon.regex.RECompiler.piece(Unknown Source)
            at net.sf.saxon.regex.RECompiler.parseBranch(Unknown Source)
            at net.sf.saxon.regex.RECompiler.parseExpr(Unknown Source)
            at net.sf.saxon.regex.RECompiler.compile(Unknown Source)
            at net.sf.saxon.regex.ARegularExpression.<init>(Unknown Source)
            at net.sf.saxon.java.JavaPlatform.compileRegularExpression(Unknown Source)
            at net.sf.saxon.Configuration.compileRegularExpression(Unknown Source)
            at net.sf.saxon.functions.RegexFunction.tryToBindRegularExpression(Unknown Source)
            at net.sf.saxon.functions.RegexFunction.makeFunctionCall(Unknown Source)
            at net.sf.saxon.functions.Replace.makeFunctionCall(Unknown Source)
            at net.sf.saxon.functions.RegexFunctionSansFlags.makeFunctionCall(Unknown Source)
            at net.sf.saxon.functions.registry.BuiltInFunctionSet.bind(Unknown Source)
            at net.sf.saxon.functions.FunctionLibraryList.bind(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parseExpression(Unknown Source)
            at net.sf.saxon.expr.parser.XPathParser.parse(Unknown Source)
            at net.sf.saxon.expr.parser.ExpressionTool.make(Unknown Source)
            at net.sf.saxon.style.StyleElement.makeExpression(Unknown Source)
            at net.sf.saxon.style.XSLSequence.prepareAttributes(Unknown Source)
            at net.sf.saxon.style.StyleElement.<unknown>(Unknown Source)
            at net.sf.saxon.style.StyleElement.processAllAttributes(Unknown Source)
            at net.sf.saxon.style.StyleElement.processAllAttributes(Unknown Source)
            at net.sf.saxon.style.PrincipalStylesheetModule.processAllAttributes(Unknown Source)
            at net.sf.saxon.style.PrincipalStylesheetModule.preprocess(Unknown Source)
            at net.sf.saxon.style.Compilation.compilePackage(Unknown Source)
            at net.sf.saxon.style.StylesheetModule.loadStylesheet(Unknown Source)
            at net.sf.saxon.style.Compilation.compileSingletonPackage(Unknown Source)
            at net.sf.saxon.s9api.XsltCompiler.compile(Unknown Source)
            at net.sf.saxon.option.cpp.Xslt30Processor.getXslt30Transformer(Unknown Source)
            at net.sf.saxon.option.cpp.Xslt30Processor.transformToFile(Unknown Source)
    Caused by: java.lang.RuntimeException: Unable to read categories.xml file
            at net.sf.saxon.regex.charclass.Categories.build(Unknown Source)
            at net.sf.saxon.regex.charclass.Categories.getCategory(Unknown Source)
            at net.sf.saxon.regex.charclass.Categories.<clinit>(Unknown Source)
            ... 47 more
    

    So it is neither xsl:include nor xsl:result-document that causes the compilation failure, it seems the HE build does not have or does not find its categories.xml file when trying to compile the regular expression in the included code.

    As a workaround, it might be possible to run SaxonC EE 11.2 without a license (-license:off), I think, as it then simply uses HE features, while somehow the EE package is correctly built to find its categories.xml so it doesn't fail on compiling regular expressions.

    I have raised https://saxonica.plan.io/issues/5372 about the categories.xml file failure.