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

The position() function in xsl:for-each-group

The position() function can be used inside xsl:for-each-group.

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,@q">
                        <group-members  id="{current-grouping-key()}"
                                    pos="{position()}">
                              <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="q0"/>
            <ccc  v="v1"
                        q="q0"/>
            <ddd  v="v1"/>
            <eee  v="v2"/>
            <fff  v="v1"
                        q="q1"/>
            <ggg  v="v3"
                        q="q1"/>
      </aaa>
Output

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


Previous chapter: Elements and attributes
Next chapter: Multiple source documents
Previous page: Groups generated with group-by using several key values
Next page: Sorting of groups

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