I have an XML document :
<Feature>
<Filter> ... </Filter>
<Filter> ... </Filter>
<Filter isTargetFilter="true"> ... </Filter>
</Feature>
Feature can hold max 3 Filter elements.
Using XSD I want to check that only last Filter element will contain an attribute "isTargetFilter".
No other Filter element can contain this attribute.
I did not find any XSD expression that can help me.
Any pointers are appreciated.
In XSD (both 1.0 and 1.1), if two elements are siblings and have the same name, then they must have the same type. (The constraint is called Element Declarations Consistent, if you want to look it up).
So the only way to do this is with XSD 1.1 assertions. Define assertions on the Feature element:
<xs:assert test="every $f in Filter[not(position()=last())] satisfies empty(@isTargetFilter)"/>
<xs:assert test="Filter[position()=last()][@isTargetFilter]"/>