xsltsaxon

Saxon HE 12.4 Fails to provide the error location in ErrorReporter


When providing a custom ErrorReporter, Saxon HE v12.4 fails to provide the error location for bad XSLT instructions.

Note: this worked in v9.8 as the report provided the Exception which contained all of the information.

Test Program

public class Test {

    public static void main(String[] args) {

        try {
            Processor processor = new Processor(false);
            processor.getUnderlyingConfiguration().setLineNumbering(true);
            XsltCompiler compiler = processor.newXsltCompiler();
            compiler.setErrorReporter(new MyErrorReporter());
            XsltExecutable stylesheet = compiler.compile(new StreamSource(new File("C:\\Temp\\badbooks.xsl")));
            System.out.println("done");
        } catch (SaxonApiException e) {
            e.printStackTrace();
        }
    }
}

Custom ErrorReporter

public class MyErrorReporter implements ErrorReporter {

    @Override
    public void report(XmlProcessingError error) {

        System.out.println("Error: " + error.getMessage());
        System.out.println("Line: " + error.getLocation().getLineNumber());
        System.out.println("Col: " + error.getLocation().getColumnNumber());
        if (error.getCause() == null)
            System.out.println("Cause is null");
    }
}

Bad XSLT containing bad instruction "xsl:for-eachx"

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:template match="BOOKLIST">
      <xsl:for-eachx select="/">
          <li><xsl:value-of select="TITLE"/></li>
      </xsl:for-eachx>
  </xsl:template>
</xsl:transform>

Error Output

Error: Unknown XSLT instruction xsl:for-eachx
Line: -1
Col: -1
Cause is null

Note: The Line and Column are -1 and the Cause is null.

I tried to debug this and found that when the StyleElement setValidationError method is called, the error location information is correct. But I couldn't work out why by the time it is passed to the ErrorReporter, the information has been lost?


Solution

  • I can confirm this has been fixed in v12.5.