Re: How to make simple type choice

Michael Kay <[email protected]>
Newsgroups gmane.text.xml.schema.devel
Message-ID <[email protected]>
  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..
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.