Subject: RE: [xsl] [XSLT 2.0] Checking that an element's value has the desired datatype? From: "Costello, Roger L." <costello@xxxxxxxxx> Date: Mon, 16 Oct 2006 19:25:01 -0400 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] [XSLT 2.0] Checking that , Michael Kay | Thread | Re: [xsl] [XSLT 2.0] Checking that , bryan rasmussen |
[xsl] Select one from Multiple Valu, oknam park | Date | [xsl] Referring to stylesheet itsel, Abel Braaksma |
Month |