Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2009, 05:21 AM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default Defining restrictions based on element/attribute values

How can I implement a custom restriction based on element or attribute value.

I have the following xml

<courses>
<course id="1">
<students>25<students>
</course>
<course id="2">
<students>30<students>
</course>
</courses>

I want to define a valid value for <students> element for each course id. There can be lots of courses. Say maximum value for students in course 1 is 30.

Some elements might be required based on the value of the course id.


How do I define an xsd for these?Is it possible?
__________________
\"Dont you ever give up!\"
 
Old May 12th, 2009, 06:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSD 1.0 doesn't support this feature (known as "co-occurrence constraints"). You can do it in XSD 1.1 using assertions. However, I'm sceptical whether this is a good design: the maximum number of students on each course looks to me like data, not metadata, and I'm not sure it really belongs in a schema.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old May 12th, 2009, 08:11 PM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default

mkhay,
I just used that as an example, I am really after the co-occurrence constraints.

Thank you very much..
__________________
\"Dont you ever give up!\"
 
Old May 13th, 2009, 03:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can try out assertions (and conditional type assignment, which is sometimes a better approach to the problem) using Saxon-SA 9.1
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
Match element based on attribute of child? transom XSLT 1 September 11th, 2005 03:26 PM
Rules based on attribute values... jacob XML 2 July 6th, 2005 01:50 PM
Modeling with restrictions on attribute value jacob XML 0 June 3rd, 2005 07:01 AM
XPath - Selecting nodes based on attribute values billy_bob_the_3rd XML 4 December 1st, 2004 06:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.