I have a simple schema that describes a component based subsystem of a game engine. Certain component types have restrictions on the combinations they can be found in.
For example, the system defines a base type Selectable
, which is in turn extended by Button
and Toggle
. A single object can only hold 1 Selectable
component.
My XSD schema mirrors this relationship (excerpt):
<xs:complexType name="Selectable">
<xs:complexContent>
<xs:extension base="Component"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Button">
<xs:complexContent>
<xs:extension base="Selectable"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Toggle">
<xs:complexContent>
<xs:extension base="Selectable">
<xs:attribute name="OnClickedCallback" type="Callback"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Now, I can manually define the aforementioned restriction with an assertation such as this one:
<xs:annotation>
<xs:appinfo>
<sch:pattern id="SingleSelectable">
<sch:rule context="Transform">
<sch:assert test="count(Button) + count(Toggle) < 2">
A transform can only have one selectable component.
</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
However, this is approach has poor scalability. I need to manually add each new type and make sure I update the numbers.
Question: Is there a way to access the type information that I defined in the xsd
file?
Something like <sch:assert test="count(*[extends('Selectable')] < 2">