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

Re: Fascinating XPath and XSD 1.1 assert problem

From: C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com>
Date: Thu, 20 Sep 2012 14:12:51 -0600
Cc: "C. M. Sperberg-McQueen" <cmsmcq@blackmesatech.com>, "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-Id: <BA2826CD-81B7-442C-AA6B-4EA67731671D@blackmesatech.com>
To: "Costello, Roger L." <costello@mitre.org>

On Sep 20, 2012, at 7:33 AM, Costello, Roger L. wrote:
> ...
> 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']

If the schema declares the 'units' attribute to have a fixed value of 'feet',
and the document is valid against that schema, then it matches the set
of all 'Altitude' children on 'Test' and is thus equivalent to /Test/Altitude.

> 
> 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>

XSD 1.1 Structures section 3.14.4.1 (Validation Rule: Assertion Satisfied)
(http://www.w3.org/TR/xmlschema11-1/#sec-cvc-assertion) is explicit
that before the assertion on an element (here the Test element) is
checked, the element is partially validated against its governing
element declaration and type definition (informally:  everything except
the assertions is checked), including all its children and attributes.  
When the assertion is checked, it's checked against an XDM instance built
using the result of that partial validation, so in the XDM used to check
the assertion on the 'Test' element, the 'Altitude' elements should be
fully and normally typed; in particular, they will have the fixed-value 
attribute checked and supplied.

The assertion on Type should then fail with a quantification error, since
the first argument of 'eq' (Altitude[@units eq 'feet']/@reference) matches 
multiple elements.

If you delete the second Altitude element, then the document should
be valid.  If you delete the first Altitude element, I think the document
should be invalid.


-- 
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com 
* http://cmsmcq.com/mib                 
* http://balisage.net
****************************************************************
Received on Thursday, 20 September 2012 20:13:15 GMT

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