This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: 2 level Grouping through attributes
- From: ronald heller <ronald at salience dot nl>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 11 Feb 2002 13:49:43 +0100
- Subject: Re: [xsl] 2 level Grouping through attributes
- Reply-to: xsl-list at lists dot mulberrytech dot com
Try the following:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="level1" match="XML_OUTPUT/@UserID" use="." />
<xsl:key name="level2" match="XML_OUTPUT/@CategoryID" use="." />
<xsl:template match="/">
<ROOT>
<xsl:for-each select="//XML_OUTPUT[generate-id(@UserID) =
generate-id(key('level1', @UserID)[1])]">
<xsl:variable name="user">
<xsl:value-of select="@UserID" />
</xsl:variable>
<xsl:comment>
<xsl:value-of select="generate-id(@UserID)" />
</xsl:comment>
<USER ID="{$user}">
<xsl:for-each select="//XML_OUTPUT[generate-id(@CategoryID)
= generate-id(key('level2', @CategoryID)[1]) and @UserID=$user]">
<xsl:variable name="category">
<xsl:value-of select="@CategoryID" />
</xsl:variable>
<CATEGORY ID="{$category}" TITLE="{@CategoryTitle}">
<xsl:for-each
select="//XML_OUTPUT[@CategoryID=$category and @UserID=$user]">
<CONTENT_ITEM ID="{@ContentItemID}"
TITLE="{@ItemTitle}">
</CONTENT_ITEM>
</xsl:for-each>
</CATEGORY>
</xsl:for-each>
</USER>
</xsl:for-each>
</ROOT>
</xsl:template>
</xsl:stylesheet>
Cheers RH
At 09:35 AM 2/11/02 +0200, you wrote:
>Hi,
>
>I am trying to achieve multi level grouping (actually two levels) of the
>next XML.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list