Bug #6238
closedXPath error information is lost in XSLT
100%
Description
If I run the XPath processor with an XPath expression that has an error, I get an accurate error location by catching the SaxonApiException exception:
XPath expression: 1 , (4, 4) eq (88, 4)
try{
XPathCompiler compiler = processor.newXPathCompiler();
}
cath(SaxonApiException e){
XPathException cause = (XPathException)e.getCause();
cause.getLocator().getColumnNumber(); // << accturate error position = 9
}
However, if I use the same XPath expression in an XSLT expression, such as <xsl:value-of select="..."/>, the XPath error location information is lost:
XsltCompiler compiler = processor.newXsltCompiler(); compiler.setErrorReporter(new MyErrorReporter));
MyErrorReporter.report(XmlProcessingError error) << this error only contains information about the location of the XSLT expression, the XPath error location is lost.
I have found this source code in StyleElement.java:
public void compileError(XmlProcessingError error) {
XmlProcessingIncident.maybeSetHostLanguage(error, HostLanguage.XSLT);
// Set the location of the error if there is no current location information,
// or if the current location information is local to an XPath expression, unless we are
// positioned on an xsl:function or xsl:template, in which case this would lose too much information
if (error.getLocation() == null ||
((error.getLocation() instanceof Loc ||
error.getLocation() instanceof Expression) && !(this instanceof StylesheetComponent))) {
XmlProcessingIncident.maybeSetLocation(error, this);
}
getCompilation().reportError(error);
}
It seems to overwrite the original XPath error location. Why is the original XPath error location not kept, for instance in a getCause().
Please register to edit this issue