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, Priscilla Walmsley. 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 TypeName | Type |
$arg |
xs:anyAtomicType? |
return value |
xs:double |
Examples<xsl:variable name="priceDoc" select="doc('https://www.datypic.com/functx./input/prices.xml')"/>
|
XPath 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 |
Recommended Reading:
|