Is it possible to define in XML Schema an condition based on attribute value? For example, when test@attrib="one", I want one-element to be allowed and mandatory or when test@attrib="two", I want two-element to be allowed and mandatory.
For example, valid documents are:
<root>
<test attrib="one"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
<one-element>
</one-element>
</root>
or
<root>
<test attrib="two"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
<two-element>
</two-element>
</root>
Wrong documents:
<root>
<test attrib="one"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
</root>
or
<root>
<test attrib="two"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
<one-element>
</one-element>
</root>
Is it possible in XSD?
Not within the same type. You would need to define a different type for each of the different options.
UPDATE
To re-use type definitions in your schema:
This will validate:
and