I have xml file that seems like that
<doc>
<field name="simple_meta">book</field>
<field name="complex_meta">journal</field>
<field name="text_date">some text</field>
</doc>
I would like to validate element text by pattern based on value in attribute "name". that is, if the value of attribute is "simple_meta" I want to make the "simpleRestriction" validation, in case of the "complex_meta" to make the "complexRestriction" validation. The problem is that I cannot define element with same name under the same node. Can someone to help me to resolve this problem?
<xs:schema ......>
<xs:simpleType name="simpleRestriction">
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="complexRestriction">
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
<xs:pattern value="([\w])*"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="str">
<xs:complexType>
<xs:simpleContent>
<xs:extention base="simpleRestriction">
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="simple_meta"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extention>
</xs:simpleContent>
</xs:ComplexType>
</xs:element>
<xs:element name="str">
<xs:complexType>
<xs:simpleContent>
<xs:extention base="complexRestriction">
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="complex_meta"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extention>
</xs:simpleContent>
</xs:ComplexType>
</xs:element>
</xs:schema>