...

View Full Version : XML Schema and Math



Tails
02-27-2009, 04:04 AM
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.



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

oesxyl
02-27-2009, 05:59 AM
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.



<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.

see this for sum of a nodeset:
http://www.codingforums.com/showpost.php?p=785252&postcount=4
I hope will help you
best regards

Tails
02-28-2009, 01:10 AM
Thanks, but I meant I need to know if XML Schemas have such a way to check this.

oesxyl
02-28-2009, 08:11 AM
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

Tails
02-28-2009, 08:20 AM
Thanks :). Powerful stuff. That's just what I needed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum