XSLT and XPath function reference in alphabetical order

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z



Rounding functions for numeric types


XPath 1.0

Return value:

The next lowest integer of the number passed on as argument – after rounding down. In XPath 1.0, the return value is of number type, in XPath 2.0 of xs:double type.




The number to be rounded. In XPath 2.0 this number has to correspond to one of the numeric data types or to a type derived thereof. Whereas, in XPath 1.0 an implicit cast according to the number() function is performed for floor().

Purpose of use:

The fn:floor() function rounds down a decimal number passed on to it to the next lowest integer. When doing so, the data type of the number is preserved. If the input number is already an integer, the value remains unchanged. If the input value does not belong to one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer or to a type derived from these, a type error is reported.

If the input value is of xs:untypedAtomic type, it is casted by type promotion to xs:double.

If the input type is a type derived from one of the numeric base types (derived type), the rounding result is returned typed with the appropriate base type.

If the empty sequence is passed on to the funtion, it returns the empty sequence. If the input value is NaN (for the input type xs:double or xs:float), NaN is likewise returned.


Input values of the xs:double or xs:float type which are +0 (positive zero) or -0 (negative zero) are returned unchanged.


fn:floor(1.1) 1
fn:floor(-1.1) -2
fn:floor(2.0) 2
fn:floor('2.2') type error
fn:floor('a_string') type error
fn:floor(16 div 3) 5
fn:floor(1 div 0)INF
fn:floor(-1 div 0)-INF

Table: examples for calling the fn:floor() function

In XPath 1.0, the call of floor() with a string argument successfully convertible to numeric type returns a number, otherwise NaN: So, floor('2.2') returns the number 2, whereas the passing on of a non-convertible character string as in the case of floor('a_string') results in the value NaN.

Function definition:

XPath 1.0:

floor(number)=> number

XPath 2.0:

fn:floor($arg as numeric?) as numeric?


<< back next >>




Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany