Project

Profile

Help

Support #3446

closed

How can i see which attribute has an invalid value?

Added by Gerben Abbink over 6 years ago. Updated over 6 years ago.

Status:
Resolved
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2017-09-15
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

This stylesheet (the stylesheet is just an example) produces an error in line 4:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

	<xsl:number count="aaa///bbb" from="aaa///bbb"></xsl:number>

</xsl:template>

</xsl:stylesheet>

My installed error listener is called with parameter e, an XPathException.

The only information i can retreive is this:

e.getLocator().getLineNumber() = 4

e.getMessage() = Unexpected token "/" at start of expression.

There is no indication which one of the two attributes is wrong. I tried

e.getCause() = null

e.getException() = null

e.getErrorObject() = null

There is also no information about the location of the error in the XPath expression. However, if i evaluate "aaa///bbb" using XPathCompiler, an exception SaxonApiException is thrown and getCause() (also an XPathException) gives me the actual location, via getLocator().getColumnNumber(), so that information seems to be available.

How can i tell which one of the attribute values is wrong (in Java code) and what the position of the error in the XPath expression is?

Thank you.


Files

exception.tiff (287 KB) exception.tiff Michael Kay, 2017-09-15 13:28
Actions #1

Updated by Michael Kay over 6 years ago

In the attached debugger screenshot !!

you can see that XPathException.locator.containingLocation.attributeName contains the name of the attribute in error.

Of course this won't always be available and you must write your ErrorListener carefully to check that what you are looking for is actually there.

The location in this case is a NestedLocation, consisting of a ContainerLocation which identifies where the XPath expression is to be found (the line, column, element name, and attribute name in the XSL stylesheet, and in fact a reference to the actual element node in the stylesheet tree), plus local information (line and column number) for the actual error within the XPath expression.

SAX only gives us the line/column of the ">" at the end of the start tag, so we don't actually know the line number on which the attribute appears, so this is the best we can do.

Actions #2

Updated by Gerben Abbink over 6 years ago

Thank you very very much for your quick response, I could not find it

myself. It works perfectly: Attribute name and error offset in the XPath

expression are both available.

On Fri, Sep 15, 2017 at 1:31 PM, Saxonica Developer Community <

> wrote:

Actions #3

Updated by Michael Kay over 6 years ago

  • Status changed from New to Resolved

Note that if you're looking for really precise information (e.g. to position a cursor on the error within the attribute value) then you need to be aware that Saxon sees the attribute after attribute-value-normalization. If you've got access to the raw attribute (which Saxon hasn't...) then you need to simulate the process of attribute-value-normalization and create a map from pre-normalization positions to post-normalization positions.

Please register to edit this issue

Also available in: Atom PDF