O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

number()

Converts its argument to a number.

Syntax

[1.0] number number(object?)
[2.0] xs:double number()
[2.0] xs:double number(xs:anyAtomicType)

Inputs

[1.0] An object.

[2.0] An xs:anyAtomicType value.

Output

A number. If no argument is passed to the number function, the context item is used. The specific rules for converting the argument to a number are different for XSLT 1.0 and 2.0.

[1.0] Here are the rules for XSLT 1.0:

  • If the argument is a boolean value, the value true is converted to the number 1; the value false is converted to the number 0.

  • If the argument is a node-set, the node-set is converted to a string as if it were passed to the string() function, and then that string is converted to a number like any other string. (Remember that the string() function returns the string value of the first node in the node-set.)

  • If the argument is a string, it is converted as follows:

    • If the string consists of optional whitespace, followed by an optional minus sign (), followed by a number, followed by whitespace, it is converted to the floating-point value nearest to the mathematical value represented by the string. (The IEEE 754 standard defines a round-to-nearest rule; see the standard for more information.)

    • Any other string is converted to the value NaN (not a number).

  • XSLT 1.0 processors are allowed to support other datatypes. If the argument is any other type, it is converted to a number in a way that depends on that type. See the documentation for your XSLT processor to find out what ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required