xsl-list
[Top] [All Lists]

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

2006-10-17 04:19:48
Costello, Roger L. wrote:
Can you think of a value for the Altitude element that the XSLT template would reject, but a schema validator would accept?

Yes. "   23   "

Good catch! The XSLT expression should be:
      matches(flt:Aircraft/flt:Altitude, '^\s*[+\-]?[0-9]+\s$')
You do not need the backslash for the minus sign (end/beginning char class), and I am sure you would want to allow for no spaces at the end. Perhaps this is a little easier to read:

'^\s*[+-]?\d+\s*$'


What about numeric values expressed in exponentional notation? These are (with a side step to xs:double) easily castable as integer. Of course, that should only apply to values that have no decimals (not sure of reqs). If you need it, you can expand your expression so:

matches(flt:Aircraft/flt:Altitude, '^\s*[+-]?\d+([eE]+?\d+)?\s*$')

-- Abel Braaksma



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>