Allan Lewis
Allan Lewis

Reputation: 309

How can my XSD require attribute values to be sequential?

I have an element "inspection" defined in my XSD, and it has an attribute "step" of type "int". What I'd like to do is to require that the first "input" has step=1, the next has step=2, and so on. Is this possible in XSD?

XML schema extract:

<element name="inspection">
    <complexType>
        <!-- some elements -->
        <!-- other attributes -->
        <attribute name="step" type="int">
            <simpleType>
                <restriction>
                    <minInclusive value="1" />
                </restriction>
            </simpleType>
        </attribute>
    </complexType>
</element>

Upvotes: 0

Views: 129

Answers (1)

Michael Kay
Michael Kay

Reputation: 163458

It's possible in XSD 1.1 but not in XSD 1.0.

In XSD 1.1 you could write the constraint as

<xs:assert test="every $i in 1 to count(input) 
                 satisfies input[$i]/@step = $i"/>

This constraint would appear on the parent element of the input elements.

XSD 1.1 is currently implemented in Xerces and Saxon.

Upvotes: 2

Related Questions