XML Schema (XSD 1.1) Dynamic enumeration depending on other attribute -


i have rather simple xml structure;

<list... >     <members>         <person type="name_with_a">             <name>ada</name>         </person>         <person type="name_with_b">             <name>berta</name>         </person>     </members>  </list> 

i want restrict value of 'name' set of names, depending on value of attribute 'type' of element 'person'.

so, example, if <person type="name_with_a">, names

  • anna
  • ada
  • amanda

should valid , if <person type="name_with_b">, only

  • berta,
  • bob
  • bret

should valid values <name> element.

according this question created following schema:

<xs:schema xmlns:vc="http://www.w3.org/2007/xmlschema-versioning" vc:minversion="1.1"  xmlns:xs="http://www.w3.org/2001/xmlschema">  <xs:element name="list"> </xs:element>  <xs:element name="person">     <xs:complextype>         <xs:sequence>             <xs:element ref="name"/>         </xs:sequence>         <xs:attribute name="type" use="required">             <xs:simpletype>                 <xs:restriction base="xs:string">                     <xs:enumeration value="name_with_a"/>                     <xs:enumeration value="name_with_b"/>                 </xs:restriction>             </xs:simpletype>         </xs:attribute>     </xs:complextype> </xs:element>  <xs:element name="name">     <xs:alternative test="@type='name_with_a'" type="choice_names_a"/>     <xs:alternative test="@type='name_with_b'" type="choice_names_b"/>       <xs:alternative type="xs:error"/> </xs:element>  <xs:element name="members">     <xs:complextype>         <xs:sequence>             <xs:element ref="person" maxoccurs="unbounded"/>         </xs:sequence>     </xs:complextype> </xs:element>  <xs:simpletype name="choice_names_a">     <xs:restriction base="xs:string">         <xs:enumeration value="anna"/>         <xs:enumeration value="ada"/>         <xs:enumeration value="amanda"/>     </xs:restriction> </xs:simpletype> <xs:simpletype name="choice_names_b">      <xs:restriction base="xs:string">         <xs:enumeration value="berta"/>         <xs:enumeration value="bob"/>         <xs:enumeration value="bret"/>     </xs:restriction> </xs:simpletype> </xs:schema> 

which not work me. have feeling, that, refer in test="@type='name_with_a'" @type attribute of element, false.

i tried test="list / members / person / @type='name_with_a'" no success.

you have right idea in using conditional type assignment, you're applying wrong element. instead of applying name, have apply person (the element type vary according type attribute). there, can vary content model of person have name elements of differing types.

see how make type depend on attribute value using conditional type assignment.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -