Project

Profile

Help

Bug #6238

closed

XPath error information is lost in XSLT

Added by Gerben Abbink about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Diagnostics
Sprint/Milestone:
-
Start date:
2023-11-02
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
12, trunk
Fix Committed on Branch:
12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

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

Also available in: Atom PDF