I have the following XML-snippet.
<grade term="One" type="simple">4.7</grade>
<grade term="Two" type="complex">2.1</grade>
The attribute type can either be "simple" or "complex". The simple type can contain all decimals from 1.0 to 5.0 and the complex type can only contain the values match the pattern [123]\.[037]|5\.0|4\.[07].
How can I build an XSD to validate the content of the grade depending on the selected type (either simple or complex) ?
I've come up with:
<xs:simpleType name="complex">
<xs:restriction base="xs:decimal">
<xs:minInclusive value="1.0"/>
<xs:maxInclusive value="5.0"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="simple">
<xs:restriction base="xs:decimal">
<xs:pattern value="[123]\.[037]|5\.0|4\.[07]"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="gradeType">
<xs:simpleContent>
<xs:extension base="complex">
<xs:attribute name="term" use="required" type="xs:NCName"/>
<xs:attribute name="type" use="required" type="complex"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
but this generates a lot of errors:
Cvc-datatype-valid.1.2.1: 'simple' Is Not A Valid Value For 'decimal'., Line '8', Column '66'. Cvc-attribute.3: The Value 'simple' Of Attribute 'type' On Element 'grade' Is Not Valid With Respect To Its Type, 'complex'., Line '8', Column '66'. Cvc-datatype-valid.1.2.1: 'simple' Is Not A Valid Value For 'decimal'., Line '9', Column '66'. Cvc-attribute.3: The Value 'simple' Of Attribute 'type' On Element 'grade' Is Not Valid With Respect To Its Type, 'complex'., Line '9', Column '66'. Cvc-datatype-valid.1.2.1: 'simple' Is Not A Valid Value For 'decimal'., Line '10', Column '66'. Cvc-attribute.3: The Value 'simple' Of Attribute 'type' On Element 'grade' Is Not Valid With Respect To Its Type, 'complex'., Line '10', Column '66'.
Thanks a lot :-)