Re: Restricting two attributes to be unequal

Hi Brett,

> What I would like to do firstly is to prevent attribute values
> "from" and "to" from being equal in documents based on this schema,
> forcing them to be unequal. A unique or key won't do as I want to
> force uniqueness over two attributes.
>
> Out of interest, if I can force them to be unequal, can I also force
> from<to?

You can do neither with XML Schema; of the schema languages currently
available, only Schematron is expressive enough for this kind of
constraint. For example, you can use the Schematron rule:

  <sch:rule context="myelement">
    <sch:assert test="@from &lt; @to">
      The value of the from attribute must be less than the value of
      the to attribute.
    </sch:assert>
  </sch:rule>

See http://www.topologi.com/resources/schtrn_xsd_paper.html to learn
how to embed Schematron into XML Schema so that tools such as
Topologi's Schematron Validator can automatically validate against
both.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Saturday, 27 September 2003 06:17:39 UTC