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



Context information within a sequence


XSLT 2.0

Return value:

A sequence consisting of one or more items; the currently processed group of a xsl:for-each-group instruction.



No arguments.

Purpose of use:

When performing a xsl:for-each-group instruction, for each determined group in a row the template block contained in xsl:for-each-group is instantiated, whereby each currently processed group is referred to as Current Group.

During the processing of the groups, the first member of each group (initial item) is considered as context item. The total number of the groups to be processed makes the context size and the position of the group in the processing order makes its context position. The functions fn:position() and fn:last() return, used here, appropriate values.

In the template block of xsl:for-each-group, the current-group() function is used in order to make resource to the members of this group as a sequence, for example, in order to output the string values of all group members with xsl:value-of. The function returns – since groups (must) have at least one member – a sequence of at least one item.

If the function is called up outside the context of the xsl:for-each-group processing, it returns the empty sequence.

No current-group() in XPath patterns:
The current-group() function is not permitted as part of XPath patterns. If used in XPath patterns, a static error will occur which makes the processing of the stylesheet impossible.


(Translated from the German data2type XSLT 2.0 reference, xsl:for-each-group element, example 2.)

Source document:

<?xml version="1.0" encoding="UTF-8"?>
   <city country="de">
   <city country="de">
   <city country="fr">
   <city country="de">

XSLT stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
   <xsl:template match="root">
         <xsl:for-each-group select="city" group-by="@country">
                  <xsl:value-of select="current-grouping-key()"></xsl:value-of>
                  <xsl:for-each select="current-group()">
                        <xsl:value-of select="name"></xsl:value-of>


<?xml version="1.0" encoding="UTF-8"?>

In this example the cities are grouped by means of their country codes ("de" or "fr"). The current-group function returns all current group members (Berlin, Hamburg and Ludwigshafen or Paris) for each loop run.

Function definition:

XSLT 1.0:

The function is not available.

XSLT 2.0:

current-group() as item()*


<< 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