Value arithmetic required - attributes
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
Description
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.
Analysis
FV
This is an OPERATION on two ATTRIBUTES raising a FLAG. Axis is attribute
CoConstraintDimensionSource: |
CoConstraintDimensionDestination: |
CoConstraintDimensionType: |
CoConstraintDimensionEffect: |
CoConstraintDimensionAxis: |
Possible solutions
Relax NG
Schematron
Check clause
A possible check-clause solution:
<xsd:complexType name="MinMax"> <xsd:annotation><xsd:appinfo><sch:pattern><sch:rule> <sch:assert test="@min <= @max"> The 'max' attribute must be at least as large as the 'min' attribute. </sch:assert> </sch:rule></sch:pattern></xsd:appinfo></xsd:annotation> <xsd:attribute name="min" type="xsd:int"/> <xsd:attribute name="max" type="xsd:int"/> <!--* ... *--> </xsd:complexType>
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"/> </xsd:attribute> </xsd:attributeGroup>
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"/> </xsd:alt> </xsd:complexType>