Restriction on elements depending on attributes in XSD 1.1

70 views Asked by At

I need to define the following situation in my XSD Schema. This is an example of my XML:

<initialization>

  <stat name="SelfActualization" range="" init="" tickValue="" colorR="" colorG="" colorB=""/>
  <stat name="Social" range="" init="" tickValue="" colorR="" colorG="" colorB=""/>

  <staticAction name="Study" >
    <SelfActualization reqPoints="0" gainedPoints="0" />
    <Social reqPoints="0" gainedPoints="0" />
  </staticAction>

</initialization>

I can define as many "stat" elements as I want (in this case only 2) and I already managed to obtain this behavior. What I don't know how to do is: in any of my "StaticActions" I need that all the "stats" previously defined above are named again (as elements), and in the same order they have been defined at the beginning. As we can see in the example indeed both "SelfActualization" and "Social" are there and in the right order. If another "stat" not defined before, or if one of the "stats" defined is missing, or if the order is wrong, the XML has to be refused. Thanks in advance..

1

There are 1 answers

5
Michael Kay On

If I have understood correctly, then on the declaration of the initialization element, add the assertion

<xs:assert test="every $sa in staticAction 
                 satisfies deep-equal(stat/@name,
                              $sa/child::*/local-name())"/>