[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Multiple Level Grouping

Subject: Re: Multiple Level Grouping
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 26 Sep 2002 20:32:37 +0100
xsl for each multiple
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.