Re: [xsl] How to group a list twice

Subject: Re: [xsl] How to group a list twice
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 28 May 2001 22:11:03 +0100
Hi Michael,

> but I don't know how to get the 2nd grouping working. Creating a key
> element for <secondLevel> and calling the template inside of the
> first template seems not to work.

I assume that you've got a number of record elements, each of which
has a firstLevel, secondLevel and thirdLevel element child.  Grouping
the second level follows the same principles as grouping the first
level, but rather than have a key that indexes only the first level,
you have to index the second *and first* level by concatenating their
values together:

<xsl:key name="class2"
         match="record"
         use="concat(firstLevel, ':', secondLevel)" />

Then, within the template for the firstLevel, you need to apply
templates to the records that have unique values for the concatenated
value:

<xsl:template match="record" mode="classList">
   <xsl:value-of select="firstLevel" />
   <xsl:apply-templates mode="classList2" />
      select="key('class', firstLevel)
                 [generate-id() =
                  generate-id(key('class2', concat(firstLevel, ':',
                                                   secondLevel))[1])]" />
</xsl:template>

And then, of course, a template to match the records in classList2
mode and give their values:

<xsl:template match="record" mode="classList2">
   <xsl:value-of select="secondLevel" />
   <xsl:for-each select="key('class2',
                             concat(firstLevel, ':', secondLevel))">
      <xsl:value-of select="thirdLevel" />
   </xsl:for-each>
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread