This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Multiple Level Grouping
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Ward, Charles (Todd)" <Todd dot Ward at sogeti-usa dot com>
- Cc: XSL-List at lists dot mulberrytech dot com
- Date: Thu, 26 Sep 2002 20:32:37 +0100
- Subject: [xsl] Re: Multiple Level Grouping
- Organization: Jeni Tennison Consulting Ltd
- References: <3F0182BA3661D611AFCD009027CA527A9C0B3B@cgaex05.sogeti-usa.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Charles,
> The first grouping is working fine. I then get to the second
> grouping which uses a combined key with the concat command. When I
> display the generate-id() values or the value of
> "$vPhase[generate-id() = generate-id(key('key2', concat(STRPHASE,'
> ',STRBUILDING))[1])]" it looks like I am capturing a unique value.
> However, the actual results is the same node being repeated. What I
> don't understand is why the for-each processes this multiple times
> rather than once.
You're doing:
For each unique COLUMN (by STRPHASE, and sorted by STRPHASE), create a
row:
> <xsl:for-each select="COLUMN[count(. | key('key1',
> STRPHASE)[1]) = 1]">
> <xsl:sort select="STRPHASE"/>
> <tr><td class="ReportCellGroup"
> colspan="5"><xsl:value-of select="STRPHASE"/></td></tr>
Then for each COLUMN with that STRPHRASE:
> <xsl:for-each select="key('key1', STRPHASE)">
create a variable holding COLUMNs with that STRPHRASE:
> <xsl:variable name="vPhase"
> select="key('key1', STRPHASE)" />
and for each COLUMN with that STRPHRASE and a unique STRBUILDING
create another row:
> <xsl:for-each select="$vPhase[generate-id()
> = generate-id(key('key2', concat(STRPHASE,' ',STRBUILDING))[1])]">
> <tr><td class="ReportCellGroup"
> colspan="4"><xsl:value-of select="STRBUILDING"/></td></tr>
before going on to iterate through all the COLUMNs with the same
STRPHRASE and STRBUILDING:
> <xsl:for-each select="key('key2',
> concat(STRPHASE,' ',STRBUILDING))">
> <tr>
> <td></td><td></td>
The trouble is that you're iterating *twice* through the COLUMNs --
for *every* COLUMN, you're iterating through *every* COLUMN that's
unique by STRPHRASE and STRBUILDING. You need to cut out the
intermediate xsl:for-each, to give:
<xsl:for-each select="COLUMN[count(. | key('key1', STRPHASE)[1]) = 1]">
<xsl:sort select="STRPHASE"/>
<tr>
<td class="ReportCellGroup" colspan="5">
<xsl:value-of select="STRPHASE"/>
</td>
</tr>
<xsl:variable name="vPhase" select="key('key1', STRPHASE)" />
<xsl:for-each
select="$vPhase[generate-id() =
generate-id(key('key2', concat(STRPHASE,' ',STRBUILDING))[1])]">
<tr>
<td class="ReportCellGroup" colspan="4">
<xsl:value-of select="STRBUILDING"/>
</td>
</tr>
<xsl:for-each select="key('key2', concat(STRPHASE,' ',STRBUILDING))">
<tr>
...
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list