Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Groups (7/10) >

An example of current-group() usage

The groups selected with current-group() are useful in many scenarios.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xsl:for-each-group  select="1 to 9"
                              group-by=". mod 5">
                        <item>
                              <xsl:value-of  select="string-join(for $i in current-group() return string($i),'+')"/>
                              <xsl:text>=</xsl:text>
                              <xsl:value-of  select="sum(current-group())"/>
                        </item>
                  </xsl:for-each-group>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <item>1+6=7</item>
      <item>2+7=9</item>
      <item>3+8=11</item>
      <item>4+9=13</item>
      <item>5=5</item>


Previous chapter: Elements and attributes
Next chapter: Multiple source documents
Previous page: Grouping in sequences with group-adjacent
Next page: Groups generated with group-by using several key values