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



Functions for numeric types


XPath 2.0

Return value:

A positive number which corresponds to the input value on the basis of the absolute value and the numeric type.




Optional. Any numeric value whose absolute value shall be returned while retaining the type.

Purpose of use:

The function always returns the absolute (positive) value of a number passed on to it. The function may be used when it must be ensured that a value is a positive number.

If a negative number is passed on to the function, it returns its positive, absolute value. The xs:float or the xs:double value -0 (negative zero) becomes +0 (positive zero), -INF becomes INF. If the input value is already positive, it remains unchanged.

If the empty sequence is passed on to the function, it returns the empty sequence.

The numeric type of the return value corresponds, if the value passed on is one of the numeric base types xs:float, xs:double, xs:decimal or xs:integer, to the numeric type of the input value. If, for example, a xs:integer value is passed on to the function, the output value will also have the type xs:integer (therefore, in the function signature the input and output value are generalised with numeric which represents no »real« data type, but a collective term).

If the input value is an untyped, atomic type xs:untypedAtomic, it will be cast before the evaluation by the function to xs:double by means of a type promotion.

If the input value is a type derived from one of the numeric base types (derived type), the base type will be returned for the result value. In rare cases, it is possible that fn:abs() produces an overflow error, if the value range of the resulting output type is not able to display the result.


fn:abs(1.15)  1.15
fn:abs(−1.15)  1.15
fn:abs(2)  2
fn:abs(−2)  2
fn:abs(1 div 0)  INFINITY
fn:abs(−1 div 0)  INFINITY
fn:abs('a_string')  Type error

Table: examples for the fn:abs() function

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

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