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
相关产品推荐
相关产品推荐

