XSD Schemas - Listing Based on a Value in a Document

This is the right long shot.

If I have a specific item in my XSD containing two attributes, for example NAME and VALUE, is it possible to limit the VALUE numbering based on the value in the name?

For example:

<xsd:complexType name="ConfigDef"> <xsd:attribute name="NAME" type="xsd:string"> <xsd:annotation> <xsd:documentation>The name of this Config setting.</xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="VALUE" type="xsd:string"> <xsd:annotation> <xsd:documentation>The value of this Config setting.</xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> 

I do not think it can be done. It can be done? Are there any XSD hacks to make it work?

+1
source share
1 answer

You can do it with the built-in schematron

 <xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="ConfigDef"> <xsd:annotation> <xsd:appinfo> <sch:pattern name="Test constraints on the ConfigDef element" xmlns:sch="http://purl.oclc.org/dsdl/schematron"> <sch:rule context="ConfigDef"> <sch:assert test="@NAME eq 'foo' and @VALUE = ('bar','baz')">Error message when the assertion condition is broken...</sch:assert> <sch:assert test="@NAME eq 'qux' and @VALUE = ('teh','xyz')">Error message when the assertion condition is broken...</sch:assert> </sch:rule> </sch:pattern> </xsd:appinfo> </xsd:annotation> <xsd:attribute name="NAME" type="xsd:string"> <xsd:annotation> <xsd:documentation>The name of this Config setting.</xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="VALUE" type="xsd:string"> <xsd:annotation> <xsd:documentation>The value of this Config setting.</xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:schema> 

Or you can do it with a relaxation scheme

 element ConfigDef { (( attribute NAME {'foo'}, attribute VALUE {'bar'|'baz'}) | ( attribute NAME {'qux'}, attribute VALUE {'teh'|'xyz'})) } 
+2
source

All Articles