Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    XML Schema and Math

    Is there a way to use an XML Schema to validate if elements or attributes of a given path add up to be a certain total? The only schema element I've seen that uses XPath to view multiple elements or attribues of a scope is <xs:unique>. Seems so close, if only it could take an XSL math function to evaluate. But only a few validators I've seen online support <xs:unique>, so it's difficult to experiment.

    Code:
    <pie>
    	<slice percent="20">A</slice>
    	<slice percent="85">B</slice>
    	<slice percent="15">C</slice>
    </pie>

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Tails View Post
    Is there a way to use an XML Schema to validate if elements or attributes of a given path add up to be a certain total? The only schema element I've seen that uses XPath to view multiple elements or attribues of a scope is <xs:unique>. Seems so close, if only it could take an XSL math function to evaluate. But only a few validators I've seen online support <xs:unique>, so it's difficult to experiment.

    Code:
    <pie>
    	<slice percent="20">A</slice>
    	<slice percent="85">B</slice>
    	<slice percent="15">C</slice>
    </pie>
    uniq means that something is not allowed multiple times but your constrain said that sum of all percent attribut values must be 100, is a different semantic in my opinion.
    I would prefere to validate the sum of the slice/@percent nodeset to be 100 in your case.

    Edit: see this for sum of a nodeset:
    XSL Param or Attribute?
    I hope will help you

    best regards
    Last edited by oesxyl; 02-27-2009 at 05:05 AM.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    Thanks, but I meant I need to know if XML Schemas have such a way to check this.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Tails View Post
    Thanks, but I meant I need to know if XML Schemas have such a way to check this.
    I use relaxng, I don't have so much experience with xmlschema, maybe you can use assertions:

    http://www.w3.org/TR/xmlschema11-2/#rf-assertions

    best regards

  • Users who have thanked oesxyl for this post:

    Tails (02-28-2009)

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    Thanks . Powerful stuff. That's just what I needed.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •