XPath/XQuery number function

Summary

Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double.

Signatures

fn:number(
) as xs:double
fn:number(
$arg as xs:anyAtomicType?
) as xs:double

Properties

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.
The one-argument form of this function is deterministic, context-independent, and focus-independent.

Rules

Calling the zero-argument version of the function is defined to give the same result as calling the single-argument version with the context item (.). That is, fn:number() is equivalent to fn:number(.), as defined by the rules that follow.

If $arg is the empty sequence or if $arg cannot be converted to an xs:double, the xs:double value NaN is returned.

Otherwise, $arg is converted to an xs:double following the rules of . If the conversion to xs:double fails, the xs:double value NaN is returned.

Examples

The expression fn:number($item1/quantity) returns 5.0e0.

The expression fn:number($item2/description) returns xs:double('NaN').

Assume that the context item is the xs:string value "15". Then fn:number() returns 1.5e1.

Error Conditions

A dynamic error is raised if $arg is omitted and the context item is absent.

As a consequence of the rules given above, a type error occurs if the context item cannot be atomized, or if the result of atomizing the context item is a sequence containing more than one atomic value.

Notes

XSD 1.1 allows the string +INF as a representation of positive infinity; XSD 1.0 does not. It is implementation-defined whether XSD 1.1 is supported.

Generally fn:number returns NaN rather than raising a dynamic error if the argument cannot be converted to xs:double. However, a type error is raised in the usual way if the supplied argument cannot be atomized or if the result of atomization does not match the required argument type.