Re: XSD 1.1 assert and id()
Michael Kay <[email protected]> Mon, 18 Nov 2013 12:36:39 +0000
| Newsgroups | gmane.text.xml.schema.devel |
|---|---|
| Message-ID | <[email protected]> |
XSD 1.1 states Part 1, =A73.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 =B7assessed=B7= is the (parentless) root node and XPath Functions and Operators states (=A715.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=FChrenberg = <[email protected]> wrote: > Hello, >=20 > I know that XSD 1.1 assert elements are restricted to descendent nodes = of the content node that is asserted. >=20 > 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. >=20 > 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. >=20 > I just wanted to assure, that this behaviour is related to the = 'only-descendents-rule'. >=20 > Best, >=20 > Maik >=20 > <?xml version=3D"1.0"?> > <xs:schema xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"> > <xs:element name=3D"movies"> > <xs:complexType> > <xs:sequence> > <xs:element maxOccurs=3D"unbounded" name=3D"movie"> > <xs:complexType> > <xs:sequence> > <xs:element name=3D"title" type=3D"xs:string"/> > </xs:sequence> > <xs:attribute name=3D"certificate"> > <xs:simpleType> > <xs:restriction base=3D"xs:int"> > <xs:enumeration value=3D"6"/> > <xs:enumeration value=3D"12"/> > <xs:enumeration value=3D"16"/> > <xs:enumeration value=3D"18"/> > </xs:restriction> > </xs:simpleType> > </xs:attribute> > <xs:attribute name=3D"no" use=3D"required"> > <xs:simpleType> > <xs:restriction base=3D"xs:ID"> > <xs:pattern value=3D"F[0-9]{6}"/> > </xs:restriction> > </xs:simpleType> > </xs:attribute> > </xs:complexType> > </xs:element> > <xs:element name=3D"customer"> > <xs:complexType> > <xs:sequence> > <xs:element name=3D"name" type=3D"xs:string"/> > </xs:sequence> > <xs:attribute name=3D"no" use=3D"required"> > <xs:simpleType> > <xs:restriction base=3D"xs:ID"> > <xs:pattern value=3D"K[0-9]{6}"/> > </xs:restriction> > </xs:simpleType> > </xs:attribute> > <xs:attribute name=3D"age"> > <xs:simpleType> > <xs:restriction base=3D"xs:int"> > <xs:minInclusive value=3D"12"/> > <xs:maxInclusive value=3D"110"/> > </xs:restriction> > </xs:simpleType> > </xs:attribute> > </xs:complexType> > </xs:element> > <xs:element name=3D"rentals"> > <xs:complexType> > <xs:sequence maxOccurs=3D"unbounded"> > <xs:element name=3D"rental"> > <xs:complexType> > <xs:sequence> > <xs:element name=3D"customer"> > <xs:complexType> > <xs:attribute name=3D"no" type=3D"xs:IDREF" = use=3D"required"/> > </xs:complexType> > </xs:element> > <xs:element name=3D"movie" maxOccurs=3D"unbounded"> > <xs:complexType> > <xs:attribute name=3D"no" type=3D"xs:IDREF" = use=3D"required"/> > </xs:complexType> > </xs:element> > </xs:sequence> > <xs:assert > test=3D"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> >=20 >=20 > <movies xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" > xsi:noNamespaceSchemaLocation=3D"movie-minimal.xsd"> > <movie certificate=3D"12" no=3D"F123456"> > <title>Star Wars</title> > </movie> > <customer no=3D"K999999" age=3D"14"> > <name>Max</name> > </customer> > <rentals> > <rental> > <customer no=3D"K999999"/> > <movie no=3D"F123456"/> > </rental> > </rentals> > </movies> >=20 > --=20 > Dr. Maik St=FChrenberg > Universit=E4t Bielefeld > Fakult=E4t f=FCr Linguistik und Literaturwissenschaft > Universit=E4tsstra=DFe 25 > 33615 Bielefeld > Telefon: +49 (0)521/106-2534 > E-Mail: [email protected] > http://www.maik-stuehrenberg.de > http://www.xstandoff.net >=20