[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Fascinating XPath and XSD 1.1 assert problem

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Thu, 20 Sep 2012 13:34:34 +0000

Fascinating XPath and XSD 1.1 assert problem
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



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.