Value arithmetic required - elements

Value arithmetic required - elements (a co-constraint use case)

Require the values of specified children to satisfy an equation or an inequality.

Cf. Value arithmetic required - attributes, which formulates a similar use case involving attributes (and an inequality).

Other use cases: Co-constraint Use Cases

source: Margrethe Fossberg [1]


   I would like, say, elements a, b, and c to have a min
   value of 0 and max value of 15, but the total sum of a, b and c cannot
   exceed 30.  Is this possible at all?


(Add your analysis here; see your name in pixels!)

Possible solutions

Relax NG


Check clause

If the elements a, b, c are siblings, then a simple check clause on the parent will do:

 <xsd:simpleType name="max15">
  <xsd:restriction base="xsd:decimal">
   <xsd:minInclusive value="0.0"/>
   <xsd:maxInclusive value="15.0">
 <xsd:element name="container">
       <sch:assert test="(./a + ./b + ./c) <= 30">
	The sum of a, b, and c must not exceed 30.
    <xsd:element name="a" type="this:max15"/>
    <xsd:element name="b" type="this:max15"/>
    <xsd:element name="c" type="this:max15"/>


If T is the name of the type assigned under normal circumstances to the container element, then we can write

<xsd:element name="container">
  <xsd:alt cond="./a + ./b + ./c > 30.00" type="xsd:error"/>
  <xsd:alt type="T"/>

Conditional Type

Last modified on 2 April 2006, at 13:06