Saxon HE 12.4 无法在 ErrorReporter 中提供错误位置

问题描述 投票:0回答:1

提供自定义 ErrorReporter 时,Saxon HE v12.4 无法提供错误 XSLT 指令的错误位置。

注意:这在 v9.8 中有效,因为报告提供了包含所有信息的异常。

测试程序

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();
        }
    }
}

自定义错误报告器

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");
    }
}

包含错误指令“xsl:for-eachx”的错误 XSLT

<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: Unknown XSLT instruction xsl:for-eachx
Line: -1
Col: -1
Cause is null

注:行和列均为-1,Cause 为空。

我尝试对此进行调试,发现当调用StyleElement setValidationError方法时,错误位置信息是正确的。但我不明白为什么当它传递给ErrorReporter时,信息已经丢失了?

xslt saxon
1个回答
0
投票

看起来像这个错误:

https://saxonica.plan.io/issues/6364

这将在下一个维护版本中修复。

© www.soinside.com 2019 - 2024. All rights reserved.