xsl-list
[Top] [All Lists]

Re: Grouping within sub elements

2005-01-29 02:49:58
Tempore 08:45:50, die 01/29/2005 AD, hinc in xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Steve W <lsl(_at_)btconnect(_dot_)com>:

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>