Value equality - and children of following sibling

From W3C Wiki

Value equality - and children of following sibling (a co-constraint use case)

Make the types assigned to certain children depend on the value of one child. (In this case, only the types of following siblings depend on the value.)

cf. Value-equals test required, constraint on grandchild, which appears to be essentially the same.

source: Carl Gentele [1]


Other use cases: Co-constraint Use Cases.

Description

   I need a way to validate that an element A's special elements follows when
   someone enters 'A' as a name.
   And likewise that the element B's special elements follow when someone enters
   'B' as a name. 
   The below schema is my way of expression of this ...
   Is this a good solution or is there a better way?


    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="message">
        <xs:complexType>
          <xs:choice>
            <xs:sequence>
               <xs:element name="name">
                 <xs:simpleType>
                   <xs:restriction base="xs:string">
                     <xs:enumeration value="A"/>
                   </xs:restriction>
                 </xs:simpleType>
               </xs:element>
               <xs:element name="variables">
                 <xs:complexType>
                   <xs:sequence>
                     <xs:element name="a_variable"/>
                   </xs:sequence>
                 </xs:complexType>
               </xs:element>
            </xs:sequence>
            <xs:sequence>
               <xs:element name="name">
                 <xs:simpleType>
                   <xs:restriction base="xs:string">
                     <xs:enumeration value="B"/>
                   </xs:restriction>
                 </xs:simpleType>
               </xs:element>
               <xs:element name="variables">
                 <xs:complexType>
                   <xs:sequence>
                     <xs:element name="b_variable"/>
                   </xs:sequence>
                 </xs:complexType>
               </xs:element>
            </xs:sequence>
          </xs:choice>
        </xs:complexType>
      </xs:element>
    </xs:schema>


    <?xml version="1.0" encoding="UTF-8"?>
    <message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="E:\test.xsd">
      <name>A</name>
      <variables>
        <a_variable/>
      </variables>
      <name>B</name>
      <variables>
        <b_variable/>
      </variables>
    </message>


Analysis

(Add your analysis here; see your name in pixels!)

MSM

As the original poster points out, this can be solved in XSD 1.0 without extension. On the whole, I believe the solution offered is clearer than a co-constraint solution would be.

Possible solutions

Relax NG

Schematron

Check clause

SchemaPath

Conditional Type