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

Sorting of groups

Groups created with xsl:for-each-groupCan be sorted using xsl:sort element.

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-by="@v">
                        <xsl:sort  select="current-grouping-key()"/>
                        <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="v2"
                        q="1"/>
            <ccc  v="v4"
                        q="2"/>
            <ddd  v="v1"
                        q="3"/>
            <eee  v="v2"
                        q="4"/>
            <fff  v="v1"
                        q="5"/>
            <ggg  v="v3"
                        q="6"/>
      </aaa>
Output

      <group-members  id="v1">
            <ddd  v="v1"
                        q="3"/>
            <fff  v="v1"
                        q="5"/>
      </group-members>
      <group-members  id="v2">
            <bbb  v="v2"
                        q="1"/>
            <eee  v="v2"
                        q="4"/>
      </group-members>
      <group-members  id="v3">
            <ggg  v="v3"
                        q="6"/>
      </group-members>
      <group-members  id="v4">
            <ccc  v="v4"
                        q="2"/>
      </group-members>


Previous chapter: Elements and attributes
Next chapter: Multiple source documents
Previous page: The position function in xsl:for-each-group
Next page: - - -

Kevin Carr in Stanton

Natural Skin Care and European Soaps
TickTalk 5
city of 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