As far as an XSLT processor is concerned, there is no such thing as a
mis-spelt element in an XPath. If the XPath is syntatically correct,
then that is fine.
Consider a variation on the identity template that has a template that
matches on child::authr. you can run this against any input document,
whether validated or not. If you confine yourself to validated-only
documents, then some documents may be validated against schemas were
authr is a valid element name.
On 21/02/2008, Costello, Roger L. <costello(_at_)mitre(_dot_)org> wrote:
Hi Folks,
Consider this XML document:
<?xml version="1.0"?>
<Book>
<Title>My Life and Times</Title>
<Author>Paul McCartney</Author>
<Date>1998</Date>
<ISBN>1-56592-235-2</ISBN>
<Publisher>McMillan Publishing</Publisher>
</Book>
Here is an XPath expression to count the number of <Author> elements:
count(/Book/Authr)
Notice that Author has been accidentally misspelled in the XPath
expression.
The XML document conforms to this XML Schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Book">
<xs:complexType>
<xs:sequence>
<xs:element ref="Title" />
<xs:element ref="Author" minOccurs="0"
maxOccurs="unbounded" />
<xs:element ref="Date" />
<xs:element ref="ISBN" />
<xs:element ref="Publisher" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Title" type="xs:string"/>
<xs:element name="Author" type="xs:string"/>
<xs:element name="Date" type="xs:string"/>
<xs:element name="ISBN" type="xs:string"/>
<xs:element name="Publisher" type="xs:string"/>
</xs:schema>
I executed the XPath using the non-schema-aware version of SAXON and
got the result: 0
That is what I expected.
Then I executed the XPath using the schema-aware version of SAXON and
got the same result.
That is NOT what I expected.
I expected SAXON to detect, by consulting the XML Schema, that Authr is
not a legal child of Book and generate an error at compile-time.
Note that this is a particularly troubling problem, since the XML
Schema declares the number of occurrences of the <Author> element to be
0-to-unbounded; thus, a result of 0 is a legitimate value and the
misspelling error may go undetected for a long time.
QUESTIONS
1. Is it the responsibility of a schema-aware processor to catch
misspelled tag names in XPath expressions?
2. Is there a flag that I can set in SAXON to tell it to catch such
misspelling errors?
3. Are there any XSLT/XPath 2.0 processors that will match such
misspelling errors?
4. Let me assume the answers to the three questions are No. Then ...
4.1 Is there a way to redesign the XPath such that the misspelling
error would be caught?
4.2 Is there a way to redesign the XPath such that the misspelling
error would be caught, regardless of whether a schema-aware or
non-schema-aware processor is being used?
Thanks!
/Roger
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--