W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2012

Re: Fascinating XPath and XSD 1.1 assert problem

From: Mukul Gandhi <gandhi.mukul@gmail.com>
Date: Thu, 20 Sep 2012 22:04:55 +0530
Message-ID: <CABuuzNMy2vtC6DQy0uKdVXk-=npOmPzP-Nv0NN5p8N2wFihzBA@mail.gmail.com>
To: "Costello, Roger L." <costello@mitre.org>
Cc: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Hi Roger,
   Here are the results that I observe with Xerces's XSD 1.1 validator,

a) When I run your below sample as it is, I get an assertion failure
with this additional message,

XPTY0004 - Value does not match a required type

Although, this is part of the Xerces proprietary <assert> error
reporting facility, but it indicates that the use of "eq" operator is
not right in your sample.

b) When I specify an <assert> in your sample as follows,

<xs:assert test="count(Altitude[@units eq 'feet']) = 2" />

Then this assertion evaluates to true. This means, the answer is two
for your question in case of Xerces.

On Thu, Sep 20, 2012 at 7:03 PM, Costello, Roger L. <costello@mitre.org> wrote:
> Hello Folks,
>
> I have stumbled upon a fascinating problem (I didn't recognize fully the problem until Michael Kay explained it to me).
>
> Consider the following XML document. There are two <Attitude> elements; they have a mandatory "reference" attribute and an optional "units" attribute:
>
> <Test>
>     <Altitude reference="MSL" units="feet" />
>     <Altitude reference="AGL"/>
> </Test>
>
> I want an XPath that does this test:
>
>       For the Attitude that has @units="feet", does it
>       have @reference="MSL"?
>
> Here is the XPath:
>
>       /Test/Altitude[@units eq 'feet']/@reference eq 'MSL'
>
> That XPath works fine. Notice that it uses "eq". Recall that "eq" can only be used when there is exactly one occurrence. This expression:
>
>       /Test/Altitude[@units eq 'feet']
>
> yields only one Altitude element, so it is okay to then test:
>
>       @reference eq 'MSL'
>
> Now suppose that in the XML Schema @units is declared to be fixed:
>
>       <xs:attribute name="units" type="xs:string" fixed="feet" />
>
> Although the XML instance document doesn't show @units on the second Altitude element it is there.
>
> So, given the XML Schema, does this expression still yield only one Altitude element:
>
>       /Test/Altitude[@units eq 'feet']
>
> Suppose that that expression is used in an XSD 1.1 assert element:
>
>     <xs:element name="Test">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element name="Altitude" maxOccurs="unbounded">
>                     <xs:complexType>
>                         <xs:attribute name="units" type="xs:string" fixed="feet" />
>                         <xs:attribute name="reference" use="required">
>                             <xs:simpleType>
>                                 <xs:restriction base="xs:string">
>                                     <xs:enumeration value="MSL" />
>                                     <xs:enumeration value="AGL" />
>                                 </xs:restriction>
>                             </xs:simpleType>
>                         </xs:attribute>
>                     </xs:complexType>
>                 </xs:element>
>             </xs:sequence>
>             <xs:assert test="Altitude[@units eq 'feet']/@reference eq 'MSL'" />
>         </xs:complexType>
>     </xs:element>
>
> Is this XML instance document valid:
>
> <Test>
>     <Altitude reference="MSL" units="feet" />
>     <Altitude reference="AGL"/>
> </Test>
>
> How many Attitude elements are there with @units eq "feet"? One or two?
>
> /Roger
>



-- 
Regards,
Mukul Gandhi
Received on Thursday, 20 September 2012 16:35:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 20 September 2012 16:35:43 GMT