You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Saxon HE 12.4自定义ErrorReporter无法获取XSLT错误位置问题

Saxon HE v12.4自定义ErrorReporter丢失XSLT错误位置信息

使用自定义ErrorReporter时,Saxon HE v12.4无法为无效XSLT指令提供错误位置信息。该功能在v9.8版本正常,当时报告返回的Exception包含完整信息。

调试后发现,调用StyleElement的setValidationError方法时错误位置信息正确,但传递到ErrorReporter时信息丢失,原因不明。

测试程序

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

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

包含无效指令的错误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为null。

内容的提问来源于stack exchange,提问作者safepage

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 08:13:14