XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS