[xsl] Is an XPath processor responsible for catching misspelled tag names when there is an associated Schema?

Subject: [xsl] Is an XPath processor responsible for catching misspelled tag names when there is an associated Schema?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Thu, 21 Feb 2008 08:14:25 -0500
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

Current Thread