Re: XSD 1.1 assert and id()

XSD 1.1 states Part 1, §3.13.1):

To check an assertion, an instance of the XPath 2.0 data model ([XDM]) is constructed, in which the element information item being ·assessed· is the (parentless) root node

and XPath Functions and Operators states (§15.5.2 fn:id):

If $node, or the context item if the second argument is omitted, is a node in a tree whose root is not a document node [err:FODC0001] is raised.

Taking these two statements together, using id() in an XSD assertion will always fail.

Michael Kay
Saxonica




On 18 Nov 2013, at 10:18, Maik Stührenberg <maik.stuehrenberg@uni-bielefeld.de> wrote:

> Hello,
> 
> I know that XSD 1.1 assert elements are restricted to descendent nodes of the content node that is asserted.
> 
> It seems to me, that this rule does prevent the use of the id() function, since it could be used to access nodes out of scope.
> 
> See the simple XSD below. I have a number of movies, a number of customers and rentals. Each movie has an age certificate and each customer has an age, both have an ID. Rentals should only be allowed if the customer's age is greater or equal the certificate.
> I've tested the XPath expression already with an XSLT 2.0 stylesheet and it worked with Saxon-EE, but the same Saxon-EE raises an error when used as a schema validator on the instance file below.
> 
> I just wanted to assure, that this behaviour is related to the 'only-descendents-rule'.
> 
> Best,
> 
> Maik
> 
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>  <xs:element name="movies">
>    <xs:complexType>
>      <xs:sequence>
>        <xs:element maxOccurs="unbounded" name="movie">
>          <xs:complexType>
>            <xs:sequence>
>              <xs:element name="title" type="xs:string"/>
>            </xs:sequence>
>            <xs:attribute name="certificate">
>              <xs:simpleType>
>                <xs:restriction base="xs:int">
>                  <xs:enumeration value="6"/>
>                  <xs:enumeration value="12"/>
>                  <xs:enumeration value="16"/>
>                  <xs:enumeration value="18"/>
>                </xs:restriction>
>              </xs:simpleType>
>            </xs:attribute>
>            <xs:attribute name="no" use="required">
>              <xs:simpleType>
>                <xs:restriction base="xs:ID">
>                  <xs:pattern value="F[0-9]{6}"/>
>                </xs:restriction>
>              </xs:simpleType>
>            </xs:attribute>
>          </xs:complexType>
>        </xs:element>
>        <xs:element name="customer">
>          <xs:complexType>
>            <xs:sequence>
>              <xs:element name="name" type="xs:string"/>
>            </xs:sequence>
>            <xs:attribute name="no" use="required">
>              <xs:simpleType>
>                <xs:restriction base="xs:ID">
>                  <xs:pattern value="K[0-9]{6}"/>
>                </xs:restriction>
>              </xs:simpleType>
>            </xs:attribute>
>            <xs:attribute name="age">
>              <xs:simpleType>
>                <xs:restriction base="xs:int">
>                  <xs:minInclusive value="12"/>
>                  <xs:maxInclusive value="110"/>
>                </xs:restriction>
>              </xs:simpleType>
>            </xs:attribute>
>          </xs:complexType>
>        </xs:element>
>        <xs:element name="rentals">
>          <xs:complexType>
>            <xs:sequence maxOccurs="unbounded">
>              <xs:element name="rental">
>                <xs:complexType>
>                  <xs:sequence>
>                    <xs:element name="customer">
>                      <xs:complexType>
>                        <xs:attribute name="no" type="xs:IDREF" use="required"/>
>                      </xs:complexType>
>                    </xs:element>
>                    <xs:element name="movie" maxOccurs="unbounded">
>                      <xs:complexType>
>                        <xs:attribute name="no" type="xs:IDREF" use="required"/>
>                      </xs:complexType>
>                    </xs:element>
>                  </xs:sequence>
>                  <xs:assert
>                    test="if (id(customer/@no)/@age ge id(movie/@no)/certificate) then (true()) else false()"/>
>                </xs:complexType>
>              </xs:element>
>            </xs:sequence>
>          </xs:complexType>
>        </xs:element>
>      </xs:sequence>
>    </xs:complexType>
>  </xs:element>
> </xs:schema>
> 
> 
> <movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="movie-minimal.xsd">
>  <movie certificate="12" no="F123456">
>    <title>Star Wars</title>
>  </movie>
>  <customer no="K999999" age="14">
>    <name>Max</name>
>  </customer>
>  <rentals>
>    <rental>
>      <customer no="K999999"/>
>      <movie no="F123456"/>
>    </rental>
>  </rentals>
> </movies>
> 
> -- 
> Dr. Maik Stührenberg
> Universität Bielefeld
> Fakultät für Linguistik und Literaturwissenschaft
> Universitätsstraße 25
> 33615 Bielefeld
> Telefon: +49 (0)521/106-2534
> E-Mail: maik.stuehrenberg@uni-bielefeld.de
> http://www.maik-stuehrenberg.de
> http://www.xstandoff.net
> 

Received on Monday, 18 November 2013 12:37:03 UTC