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:

An atomic value; the current value of the grouping criterion during the processing of a group formed by xsl:for-each-group.



No arguments.

Purpose of use:

With the help of the current-grouping-key() function, the current value of the grouping criterion on which the group is based can be used during the processing of a group formed by the XSLT instruction xsl:for-each-group. This value is determined by the attributes group-by or group-adjacent of the instruction. The returned value is always an atomic value (a singleton sequence) and never a sequence consisting of several values.

Outside the evaluation context of a xsl:for-each-group instruction, the function always returns the empty sequence.

No current-grouping-key() in XPath patterns:
The current-grouping-key() function is not permitted as a 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 their country codes ("de" or "fr"). The current-grouping-key() function returns the current key value by means of which the grouping was made ("de" or "fr").

Function definition:

XSLT 1.0:

The function is not available.

XSLT 2.0:

current-grouping-key() as xs:anyAtomicType


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