0

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) &lt; 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">

Selali Adobor
  • 2,060
  • 18
  • 30
  • And I forgot to note, the current assert doesn't really do anything that makes Schematron needed. It could be replaced with a choice in XSD. – Selali Adobor Oct 15 '14 at 19:13
  • possible duplicate of [How to check in XPATH if a type is equal to a type or derived from the type](http://stackoverflow.com/questions/8323452/how-to-check-in-xpath-if-a-type-is-equal-to-a-type-or-derived-from-the-type) – Paul Sweatte Jun 14 '15 at 08:31

0 Answers0