This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 2 level Grouping through attributes


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]