- From: Michael Kay <mike@saxonica.com>
- Date: Fri, 27 Aug 2010 23:14:01 +0100
- To: Karl Stubsjoen <kstubs@gmail.com>
- CC: xmlschema-dev@w3.org
You can use xs:assert for this, but conditional type assignment is probably a closer fit to the requirement - it's specifically designed to allow you to validate the element contentagainst a type chosen on the basis of the value of an attribute <xs:element name="queries"> <xs:alternative test="@name='test1'" type="type1"/> <xs:alternative type="type2"/> </xs:element> On the other hand, I often find xs:assert easier even in cases like this. Here it would be something like this: <xs:assert test="every $q in query satisfies $q/@name = if (@name='test1') then ('somename1', 'somename2') else ('somename2', 'somename3')"/> Note, with Saxon it's always a good idea to express assertions using "every X satisfies", because Saxon treats them specially from the point of view of diagnostics - you will get a list of the query elements (with line numbers) that don't satisfy the condition. Michael Kay Saxonica On 27/08/2010 10:11 PM, Karl Stubsjoen wrote: > I need to make a choice between various simple types for an attribute. > The xml may look something like this: > > <project> > <queries name="test1"> > <query name="somename1"></query> > <query name="samename2"></query> > </queries> > <queries name="test2"> > <query name="somename2"></query> > <query name="samename3"></query> > </queries> > </project> > > So basically a queries node named "test1" will have a query node with > an enumeration restriction of: > somename1 > somename2 > > And, a queries node named 'test2" will have a query node with an > enumeration restriction of: > somename2 > somename3 > > How do you achieve this? I'm looking at xs:assert but not sure I'm on > the right path. > Thanks, > Karl.. > >
Received on Friday, 27 August 2010 22:14:34 UTC