Saturday, 18 October 2014

Creating and using derived types in XML schema



Let's say I have an element defined as follows:



<xs:element name="grade">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:double">
<xs:attribute name="type" type="libNS:gradeType" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>


with my gradeType defined as follows:



<xs:simpleType name="bookFormatType">
<xs:restriction base="xs:string">
<xs:pattern value="simple|complex"/>
</xs:restriction>
</xs:simpleType>


This allows me to define grade elements like this:



<grade type="simple">2.0</grade>


This is just an example in order to illustrate the base that I'm working with. What I want to do is move simple and complex in types of their own looking similar to the following:



<xs:simpleType name="simple">
<xs:restriction base="xs:double">
<xs:pattern value="1.0|1.3|1.7|2.0|2.3|2.7|3.0|3.3|3.7|4.0|4.7|5.0"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="complex">
<xs:restriction base="xs:double">
<xs:minInclusive value="1.0"/>
<xs:maxInclusive value="5.0"/>
</xs:restriction>
</xs:simpleType>


The simple type of grade allows me to use only a limited set of choices due to a restriction in the grading scale. The complex type on the other hand allows me basically an unlimited interval between 1.0 and 5.0 since I use it to compute the arithmetic mean of multiple simple grades and round it to the closest simple grade available in an XSLT. However I have no idea how to change my gradeType in such a way so that both simple types simple and complex can be used when I create a grade element. I have read about deriving types (here: simple,complex) from a base class (here: gradeType) but it seems I simply don't get it.


No comments:

Post a Comment