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: "bryan rasmussen" <rasmussen.bryan@xxxxxxxxx>
Date: Tue, 17 Oct 2006 03:59:09 +0200
I think people have forgotten the explicit reference Roger made to
schematron, since schematron is a validation technology that can be
implemented in XSL-T it follows that the expression
matches(flt:Aircraft/flt:Altitude, '[0-9]+')
would give you the same capabilities as XML Schema datatype checking
in any actually useful scenario.

That said, this would only apply to ISO Schematron with the binding
language set to xpath 2.0

Cheers,
Bryan Rasmussen

On 10/17/06, Costello, Roger L. <costello@xxxxxxxxx> wrote:
Hi Folks,

Consider this XML document again:

<?xml version="1.0"?>
<Flight xmlns="http://www.aviation.org";>
    <Aircraft>
        <Altitude>3300</Altitude>
    </Aircraft>
</Flight>

Suppose that we want a mechanism to check that the value of the
Altitude element is an integer.

The mechanism should accept all of these as valid values:

<Altitude>3300</Altitude>
<Altitude>0</Altitude>
<Altitude>-53</Altitude>

The mechanism should reject all of these as invalid values:

<Altitude>XYZ</Altitude>
<Altitude>66.01</Altitude>
<Altitude>true</Altitude>

One mechanism is to create an XML Schema and declare Altitude as such:

<element name="Altitude" type="integer"/>

The above valid values would be accepted by a schema validator.  The
invalid values would be rejected by a schema validator.

Now consider this XSLT template:

<xsl:template match="flt:Flight">
      <xsl:choose>
            <xsl:when test="matches(flt:Aircraft/flt:Altitude,
'^[+-]?[0-9]+$')">
                  ACCEPTED: Altitude has a valid value
            </xsl:when>
            <xsl:otherwise>
                  REJECTED: Altitude has an invalid value
            </xsl:otherwise>
      </xsl:choose>
</xsl:template>

The above valid values would be accepted by the XSLT template.  The
invalid values would be rejected by the XSLT template.

QUESTION: can you think of a value for the Altitude element that the
XSLT template would accept, but a schema validator would reject?  Can
you think of a value for the Altitude element that the XSLT template
would reject, but a schema validator would accept?

Thanks!

/Roger

Current Thread