I need to make specific XSD validation for a single type of node based on an attribute value: XSD 1.1 and xsd:alternative should be my friends.
BUT with the following (most simple) example:
<xsd:complexType name="BaseType">
<xsd:attribute name="type"
type="xsd:string"
use="required" />
</xsd:complexType>
<xsd:complexType name="NamedType">
<xsd:complexContent>
<xsd:extension base="BaseType">
<xsd:attribute name="path"
type="xsd:string"
use="required" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="TaggedType">
<xsd:complexContent>
<xsd:extension base="BaseType">
<xsd:attribute name="tag"
type="xsd:string"
use="required" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="MyRoot">
<xsd:complexType>
<xsd:choice minOccurs="1">
<xsd:element name="MyType"
type="BaseType">
<xsd:alternative test="@type='Named'"
type="NamedType"/>
<xsd:alternative test="@type='Tagged'"
type="TaggedType"/>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
When I am loading the XSD (using QXmlSchema class from Qt 4.7.4 but I think this is an XSD issue rather than a Qt one) I get the following error:
Error XSDError in Unknown location, at line 93, column 74: test attribute of alternative element contains invalid content: {@type='Named'}.
I have tried also "@type eq 'Named'" in the alternative test condition and a ton of other sensible and less sensible variations ... none passed :/
Any help will be much appreciated! Thanks!