RE: [xsl] [XSLT 2.0] Checking that an element's value has the desired datatype?

Subject: RE: [xsl] [XSLT 2.0] Checking that an element's value has the desired datatype?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Tue, 17 Oct 2006 08:25:48 -0400
> Schemas should be used to impose conditions that imply "this document
is
> meaningless, it doesn't make sense, it should be thrown in the bin
and not
> processed". They should not be used for conditions that say "if this
> condition is true [or false], then special action is needed" - that's
much
> better done through a query language.

Schematron is a schema language. It expresses things like "if this
condition is true [or false], then fire this diagnostic.

For example, here is how to express in Schematron the constraint that
the aircraft must be at least 500 feet above all the vertical
obstructions:

<sch:pattern name="Check that the Aircraft Altitude is at least
                               500 feet higher than the top of all
VerticalObstructions">
      <sch:rule context="flt:Flight">
         <sch:assert test="every $j in flt:VerticalObstruction
satisfies if ($j/flt:Height) then number(flt:Aircraft/flt:Altitude) gt
number($j/flt:Height + $j/flt:Elevation + 500) else
number(flt:Aircraft/flt:Altitude) gt number($j/flt:Elevation + 500)"
          diagnostics="Aircraft-Too-Low">
              The Aircraft Altitude must be at least 500 feet higher
              than the top of each VerticalObstruction.
         </sch:assert>
     </sch:rule>
</sch:pattern>

Note the "diagnostics" reference.  If the XML document should fail the
constraint then the diagnostic is invoked:

<sch:diagnostic id="Aircraft-Too-Low">
        Warning! The Aircraft Altitude is too low!
        Current Aircraft Altitude = <sch:value-of
select="flt:Aircraft/flt:Altitude"/>
        Maintain an altitude of at least 500 feet above each
VerticalObstruction
</sch:diagnostic>

Isn't this a valid use of a schema language?  /Roger


-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: Tuesday, October 17, 2006 8:00 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] [XSLT 2.0] Checking that an element's value has the
desired datatype?

> > "Check that the aircraft's altitude is at least 500 feet
> above all the
> > vertical obstructions"
>
> If you are using XML and a validation tool to work out if
> there is an obstruction in the way of an aircraft then you
> might find the aircraft has hit it before the result has been
> returned...

That observation might appear flippant, but actually it's a good
illustration that this is not the right way to use validity
constraints.
Schemas should be used to impose conditions that imply "this document
is
meaningless, it doesn't make sense, it should be thrown in the bin and
not
processed". They should not be used for conditions that say "if this
condition is true [or false], then special action is needed" - that's
much
better done through a query language.

The same applies to a large number of integrity constraints you find in
database textbooks, such as "employees must be aged between 16 and 65".

Michael Kay
http://www.saxonica.com/

Current Thread