Value arithmetic required - attributes

From W3C Wiki
Revision as of 07:11, 5 April 2006 by (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Value Arithmetic Required - Attributes (a co-constraint use case)

Require that the value of one attribute be greater than or equal to that of another attribute.

Cf. Value arithmetic required - elements, which supplies a similar use case involving elements (and unlike this use case actually does require arithmetic).

source: Joan Jesus Pujol Espinar [1]

Other use cases: Co-constraint Use Cases


   If I declare two attributes named
   min and max, can I control that
   max<=min with a schema? 

Note that the schema for schema documents has a similar constraint involving minOccurs and maxOccurs.



This is an OPERATION on two ATTRIBUTES raising a FLAG. Axis is attribute


Possible solutions

Relax NG


Check clause

A possible check-clause solution:

 <xsd:complexType name="MinMax">
      <sch:assert test="@min <= @max">
       The 'max' attribute must be at least as large as the 'min' attribute.
  <xsd:attribute name="min" type="xsd:int"/>
  <xsd:attribute name="max" type="xsd:int"/>
  <!--* ... *-->

Conditional assignment

One of the possible solutions is:

<xsd:attributeGroup name="MinMax">
   <xsd:attribute name="min" type="xsd:int"/>
   <xsd:attribute name="max">
      <xsd:alt cond=". < ../@min" type="xsd:int"/>
      <xsd:alt                       type="xsd:error"/>

Conditional Type

<xsd:complexType name="MinMax">
   <xsd:alt cond="@max >= @min">
      <xsd:attribute name="min" type="xsd:int"/>
      <xsd:attribute name="max" type="xsd:int"/>