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:

A number of numeric type; the next higher or lower nearest integer of an input number after rounding, but without change of the data type. In XPath 1.0 the return value is of number type.




Optional. The number to be rounded. In XPath 2.0 this number must correspond to one of the numeric data types or a type derived thereof. Where applicable, a type promotion is tried.

Purpose of use:

The fn:round() function rounds a decimal number passed on to it up or down to the next integer. The data type of the number is maintained. If the input number is already an integer, the value remains unchanged. If the input type is a type derived from one of the numeric base types, the rounding result is returned typed with the appropriate base type.

If the input value has the xs:untypedAtomic type, this type is cast to xs:double by means of type promotion.

If the type of the input value is not xs:untypedAtomic or one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer or a typed derived from these types, a type error is reported.

If the empty sequence is passed on to the function, it also returns the empty sequence. If (for the input types xs:double or xs:float) the input value is NaNNaN is also returned.

When rounding to 0, the rounding direction has an influence on the result. So, a value rounded up from a number greater than -0,5 against 0 results in -0 (negative zero), in contrast a value rounded down from a number less than +0,5 against 0 results in +0 (positive zero). Positive and negative zero values of xs:double or xs:float type remain unchanged as input values as well as positive infinite INF or negative infinite -INF.

Behaviour under XPath 1.0:

In XPath 1.0 for round() an implicit type conversion according to the number() function for non-numeric input values is made. If in XPath 1.0 the value passed on is an empty string, the result is NaN. (Attention: the similar passing on of an empty sequence under XPath 2.0 results in an empty sequence!)


Function callResult
fn:round(-0.499999) -0 (negative zero)
fn:round(0.499999) 0 (positive zero)
fn:round(1.499999) 1
fn:round('string')Type error in XPath 2.0
round('string') (XPath 1.0)NaN in XPath 1.0

Table: examples for the call of fn:round()

Function definition:

XPath 1.0:

round(number)=> number

XPath 2.0:

fn:round($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