Re: [xsl] Grouping within sub elements

Subject: Re: [xsl] Grouping within sub elements
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Sat, 29 Jan 2005 10:49:58 +0100
Tempore 08:45:50, die 01/29/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Steve W <lsl@xxxxxxxxxxxxx>:

If I was to group all the subitems, I'd use something like <xsl:key
name="subs" match="BODY/ITEM" use="SUBITEM" />.

Can I apply the same sort of logic within an item group, to get some output
something like :


Item AA
Subitems 1, 2, 3
Item BB
Subitems 1,4
Item CC
Subitems 2, 3

Hi,

The trick is to extend the 'key' elment's 'use' attribute with more information, using the 'concat()' function.
e.g.:


<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method = "text"/>


<xsl:key name="subs" match="SUBITEM" use="concat(../ID,.)" />

<xsl:template match="ITEM">
Item <xsl:value-of select="ID"/>
Subitems <xsl:apply-templates select="SUBITEM[generate-id()=generate-id(key('subs', concat(../ID,.)))]"/>
</xsl:template>


<xsl:template match="SUBITEM">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:template>

</xsl:stylesheet>


regards, -- Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041) "Et ipsa scientia potestas est" - Francis Bacon , Meditationes sacrae

Current Thread