Description
The fn:number function constructs an xs:double value either from a node that contains a number, or from an atomic value. This function is useful for telling the processor to treat a node or value as a number, regardless of its declared type (if any). It returns the argument cast as an xs:double.
The difference between using the fn:number function and the xs:double constructor is that the fn:number function returns the value NaN in the case that the argument cannot be cast to a numeric value, whereas the xs:double constructor will raise an error.
This description is © Copyright 2007, O'Reilly Media. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book. Arguments and Return Type| Name | Type |
$arg |
xs:anyAtomicType? |
| return value |
xs:double |
Examples<xsl:variable name="priceDoc" select="doc('http://www.functx.com/input/prices.xml')"/>
|
| XSLT Example | Results |
|---|
number(
$priceDoc//prod[1]/price)
|
29.99
|
number(
$priceDoc//prod/price)
|
Error XPTY0004 |
number(
$priceDoc//prod[1]/@currency)
|
NaN
|
number('29.99')
|
29.99
|
number('ABC')
|
NaN
|
number( () )
|
NaN
|
$priceDoc//
prod/price[number() > 35]
|
<price currency="USD">69.99</price>
<price currency="USD">39.99</price>
|
See AlsoHistory |
|