By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

Uniqueness only for some attribute value

P: n/a
Hi,

I want to add uniqueness constraint for an attribute, but only for a
certain value, for example, the attribute can be 'true' or 'false' or
none, I want to allow only one 'true' value. How should I do? I tried
to use like this:
<xs:key name="attributeKey">
<xs:selector xpath="./MyElement[@myAttribute = 'true']"/>
<xs:field xpath="@myAttribute"/>
</xs:key>

but this gives validation error in xsd.
Any help is appreciated.

Thanks.
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
kate wrote:
I want to add uniqueness constraint for an attribute, but only for a
certain value, for example, the attribute can be 'true' or 'false' or
none, I want to allow only one 'true' value. How should I do? I tried
to use like this:
<xs:key name="attributeKey">
<xs:selector xpath="./MyElement[@myAttribute = 'true']"/>
<xs:field xpath="@myAttribute"/>
</xs:key>


AFAIK XSD doesn't allow that. It only supports very limited subset of XPath.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2

P: n/a
> AFAIK XSD doesn't allow that. It only supports very limited subset of XPath.

Thanks for reply.

And do you know how I can use conditions in xsd? For example, I would
like to restrict some element or attribute under a certain condition,
like when an attribute is some value. Thanks in advance.
Nov 12 '05 #3

P: n/a
kate wrote:
And do you know how I can use conditions in xsd? For example, I would
like to restrict some element or attribute under a certain condition,
like when an attribute is some value. Thanks in advance.


I'm afraid it's the same anser - you cannot. XSD Schema doesn't support
co-occurence constraints. Try different schema language (such as
schematron or relaxng) to validate such constraints.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.