Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Groups (2/10) >

Grouping with group-adjacent

The group-adjacent attribute of xsl:for-each-group element enables "grouping of neighbors". The nodes are collected in the same group if they share a value specified by the group-adjacent attribute and in the population selected by select of xsl:for-each-group are neighbors, it means that there is no item with different value between them.
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="*"
                              group-adjacent="@v">
                        <xsl:apply-templates  select="."/>
                        <group-members  id="{current-grouping-key()}">
                              <xsl:apply-templates  select="current-group()"/>
                        </group-members>
                  </xsl:for-each-group>
            </xsl:template>

            <xsl:template  match="*">
                  <xsl:copy-of  select="."/>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb  v="a2"/>
            <ccc  v="1"/>
            <ddd  v="1"/>
            <eee  v="a2"/>
            <fff  v="a2"/>
            <ggg  v="a2"/>
            <hhh  v="1"/>
            <iii  v="zz3"/>
      </aaa>
Output

      <bbb  v="a2"/>
      <group-members  id="a2">
            <bbb  v="a2"/>
      </group-members>
      <ccc  v="1"/>
      <group-members  id="1">
            <ccc  v="1"/>
            <ddd  v="1"/>
      </group-members>
      <eee  v="a2"/>
      <group-members  id="a2">
            <eee  v="a2"/>
            <fff  v="a2"/>
            <ggg  v="a2"/>
      </group-members>
      <hhh  v="1"/>
      <group-members  id="1">
            <hhh  v="1"/>
      </group-members>
      <iii  v="zz3"/>
      <group-members  id="zz3">
            <iii  v="zz3"/>
      </group-members>


Previous chapter: Elements and attributes
Next chapter: Multiple source documents
Previous page: Grouping with group-by
Next page: Grouping with group-starting-with

Kevin Carr in Stanton

Natural Skin Care and European Soaps
Kevin Carr
Mayor Dave Shawver Stanton
Internetusers


You can also get Organic Skin Care products from Bliss Bath Body and you must check out their Natural Body Lotions and bath soaps

Now if you are looking for the best deals on surf clothing from Quiksilver and Roxy then you have to check these amazing deals here:

Hey, check out this Organic Skin Care European Soaps along with Natural Lavender Body Lotion and shea butter

and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks ing suit and swim trunks