W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2009

RE: [XML Schema 1.1] The XPath in <assert> cannot "look up" the XML tree, right?

From: Michael Kay <mike@saxonica.com>
Date: Wed, 29 Apr 2009 15:02:56 +0100
To: "'Costello, Roger L.'" <costello@mitre.org>, <xmlschema-dev@w3.org>
Message-ID: <079B87D50C324F9A89EC8A132D274EF5@Sealion>

> 
> I wish to confirm that I correctly understand the 
> specification. I believe it says the XPath in an <assert> 
> cannot "look up" the XML tree. That is, it can't reference a 
> parent, grandparent, etc. Is that correct?

Yes, that's right. The idea is that the validity of an element (or, if you
like, the rules for a type) depend only on the content of that element, and
not on the context where it is used.
> 
> Consider this instance document:
> 
> <Document classification="secret">
>     <Para classification="unclassified">
>           ...
>     </Para>
>     <Para classification="secret">
>           ...
>     </Para>
>     <Para classification="unclassified">
>           ...
>     </Para>
>     <Para classification="secret">
>           ...
>     </Para>
> </Document>
> 
> 
> Here I place an <assert> on the Para element which attempts 
> to reference the (parent) Document element:
> 
> <xs:element name="Para">
>     <xs:complexType>
>         <xs:simpleContent>
>             <xs:extension base="paraType">
>                 <xs:attribute name="classification" 
> type="classificationLevels" use="required"/>
>                 <xs:assert test="if (@classification eq 
> 'top-secret') then ../Document/@classification eq 'top-secret') ... />
>             </xs:extension>
>         </xs:simpleContent>
>     </xs:complexType>
> </xs:element>
> 

This is a rule affecting the validity of the Document, not the validity of
any Para considered in isolation. It needs to go at the Document level.

<xs:complexType name="DocumentType">
  <xs:complexContent>
    ...
    <xs:assert test="if (@classification ne 'top-secret') then
empty(Para[@classification eq 'top-secret']) else true()"/>

If you're in a world where PSVI annotations matter, each Para is valid, but
the Document is invalid.

Michael Kay
http://www.saxonica.com/
Received on Wednesday, 29 April 2009 14:03:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:11 GMT