Name

[2.0] current-group()

Returns all the items that are included in the current group.

Syntax

item()* current-group()

Inputs

None.

Output

The set of items that are included in the current group. This function is only useful inside the <xsl:for-each-group> element. Calling current-group() outside <xsl:for-each-group> returns the empty sequence.

Defined in

XSLT 2.0 section 14, “Grouping.”

Example

We’ll use a simplified version of our address book document to illustrate the current-group() function:

<?xml version="1.0"?>
<!-- simple-addresses.xml -->
<addressbook>
  <address>
    <name>Mr. Chester Hasbrouck Frisby</name>
    <city>Sheboygan</city>
    <state>WI</state>
  </address>
  <address>
    <name>Mary Backstayge</name>
    <city>Skunk Haven</city>
    <state>MA</state>
  </address>
  <address>
    <name>Ms. Natalie Attired</name>
    <city>Winter Harbor</city>
    <state>ME</state>
  </address>
  <address>
    <name>Harry Backstayge</name>
    <city>Skunk Haven</city>
    <state>MA</state>
  </address>
  <address>
    <name>Mary McGoon</name>
    <city>Boylston</city>
    <state>VA</state>
  </address>
  <address>
    <name>Ms. Amanda Reckonwith</name>
    <city>Lynn</city>
    <state>MA</state>
  </address>
</addressbook>

We’ll group these names by <state> with this stylesheet:

<?xml version="1.0"?>
<!-- current-group.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>&#xA;Here's a test of the </xsl:text> <xsl:text>current-group() function:&#xA;</xsl:text> <xsl:text>&#xA; Customers ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.