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: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 16 Oct 2006 19:22:04 +0200
Costello, Roger L. wrote:
Excellent! With this:

matches(flt:Aircraft/flt:Altitude, '[0-9]+')

I can do datatype checking, without using XML Schemas.

Not really (as Florent pointed out already). And be aware, it does not check for an xs:integer, it only checks for the existence of one or more digits inside an item. Matching are: '123ABC', 'ABC123', 'ABC1ZYX' etc. To match only digits, you must supply it with start/end matches, like so:


matches(flt:Aircraft/flt:Altitude, '^[0-9]+$')

Furthermore, it does not do the same as 'castable as'. Because a string like '1E10' is an xs:double which is castable as xs:integer. To make matters worse, the xs:string containing '1E10' cannot be cast to xs:integer directly (meaning 'castable as' would return false), it must first be converted to xs:double. Since you can only use matches() on strings, stuff like this cannot be mimicked with it.

-- Abel Braaksma
  http://www.nuntia.com

Current Thread