[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: testing for string and number in XSLT 2.0 was Re:

Subject: RE: testing for string and number in XSLT 2.0 was Re: Test For Numeric Values?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 9 Apr 2005 19:29:54 +0100
java test numeric
> EX. XML
> <?xml version="1.0" encoding="UTF-8"?>
> <example>
>     <test>132131</test>
> </example>

I'll assume there is no schema, that is, this is an untyped/unvalidated
document.

>     <xsl:variable name="x" select="example/test" as="xs:integer"/>
>     <xsl:variable name="y" select="example/test"/>
> 
>         y variable value(so we know we are selecting it): 132131
>         Test y as string:false
>         Test y as integer:false
>         x variable value:132131
>         test x as integer: true
> 
> not sure if this is what I would expect normally, the issue is related
> to an element if if has no explicitly declared data-type..

I don't know what your expectations are but these results are correct
according to the spec. If you don't validate the input document against a
schema, then the "typed value" of its nodes is untypedAtomic. If you test
($y instance of xdt:untypedAtomic) you will get the answer true.
untypedAtomic behaves essentially like XSLT 1.0 - if you use the value where
a string is expected, it's treated as a string, if you use it where an
integer is expected, it's converted to an integer.
> 
> it doesnt make much sense to me to *have* to declare something as an
> integer datatype to test if its a value is a number...whats the point?
> 
You need to distinguish "instance of" and "castable as". The "instance of"
operator is useful if you write a function that can accept arguments of
several different types and you want to test which type you have been given
(just like "instanceof" in Java). The "castable as" operator is useful when
you are given untyped data and you want to see whether its lexical form
makes it suitable for casting to a particular type such as xs:integer or
xs:date - which is where this thread started.

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.