Tarta
Tarta

Reputation: 2063

Restriction on elements depending on attributes in XSD 1.1

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..

Upvotes: 1

Views: 75

Answers (1)

Michael Kay
Michael Kay

Reputation: 163262

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())"/> 

Upvotes: 2

Related Questions