xsl-list
[Top] [All Lists]

Re: Grouping elements using XSL

2004-07-22 09:08:40




Josh,

Thanks for your help.  The solution you provided works great!!

Its going to take a while for me to fully understand what you have written,
but I'll give it a go.  I also need the code to sum the columns as well,
and print the results in the last row of the table.  Hopefully, I'll be
able to work that out with the example you have given.

Thanks again

Mike




|---------+---------------------------->
|         |           "Josh Canfield"  |
|         |           <joshcanfield(_at_)gma|
|         |           il.com>          |
|         |                            |
|         |           07/21/04 09:12 PM|
|         |           Please respond to|
|         |           xsl-list         |
|         |                            |
|---------+---------------------------->
  
--------------------------------------------------------------------------------------------------------------|
  |                                                                             
                                 |
  |       To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com            
                                                  |
  |       cc:                                                                   
                                 |
  |       Subject:  Re: [xsl] Grouping elements using XSL                       
                                 |
  
--------------------------------------------------------------------------------------------------------------|




Here is a solution for your problem to mull over...

Enjoy,
Josh


<?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

  <!-- key to return the ROW nodes with matchine DAYSOPEN nodes-->
  <xsl:key name="days-open" match="ROW" use="DAYSOPEN"/>
  <!-- key to return the ROW nodes with matchine MONTH nodes-->
  <xsl:key name="month" match="ROW" use="MONTH"/>

  <xsl:template match="/REPORT">
    <table>
    <!-- Build Header Row -->
    <tr><th>Days Open</th>
    <xsl:for-each select="DATA/ROW[count(. | key('month',MONTH)[1])=1]">
      <xsl:sort select="MONTH" data-type="text"/>
      <th><xsl:value-of select="MONTH"/></th>
    </xsl:for-each>
    <th>Total</th>
    </tr>

    <!-- Build the content Rows -->
    <!-- Iterate over the set of ROW nodes containing the first unique
DAYSOPEN value -->
    <xsl:for-each select="DATA/ROW[count(. | key('days-open',
    DAYSOPEN)[1])=1]">
      <xsl:sort select="DAYSOPEN" data-type="number"/>
      <!-- Hold on to the current days-open -->
      <xsl:variable name="days-open" select="DAYSOPEN"/>
      <tr>
        <td><xsl:value-of select="$days-open"/></td>
        <!-- Iterate over a set of ROW nodes contianing the first
unique MONTH value -->
        <xsl:for-each select="../ROW[count(. | key('month',MONTH)[1])=1]">
          <xsl:sort select="MONTH" data-type="text"/>
          <!-- create a cell containing the sum COUNT nodes from the
ROW nodes with common DAYSOPEN and MONTH nodes-->
          <td><xsl:value-of select="sum(../ROW[(DAYSOPEN=$days-open)
and (MONTH=current()/MONTH)]/COUNT)"/></td>
        </xsl:for-each>
        <!-- create a cell containing the sum of the COUNT nodes of
ROWs with a common DAYSOPEN node-->
        <td><xsl:value-of
        select="sum(../ROW[DAYSOPEN=$days-open]/COUNT)"/></td>
      </tr>
    </xsl:for-each>
    </table>
  </xsl:template>

</xsl:stylesheet>

On Wed, 21 Jul 2004 19:21:33 -0400, 
michael(_dot_)s(_dot_)eberhart(_at_)verizon(_dot_)com
<michael(_dot_)s(_dot_)eberhart(_at_)verizon(_dot_)com> wrote:


Hi,

I'm new to XSL and need help (that is an understatement) grouping
elements
for display.  I have been reading up on several web sites, but I am still
extremely confused.

My data looks like this:

<REPORT>
     <DATA>
           <ROW>
                 <DAYSOPEN>12</DAYSOPEN>
                 <REGION>MA</REGION>
                 <MONTH>2004-01</MONTH>
                 <COUNT>14</COUNT>
           </ROW>
           <ROW>
                 <DAYSOPEN>15</DAYSOPEN>
                 <REGION>RI</REGION>
                 <MONTH>2004-02</MONTH>
                 <COUNT>14</COUNT>
           </ROW>
           <ROW>
                 <DAYSOPEN>12</DAYSOPEN>
                 <REGION>OH</REGION>
                 <MONTH>2004-01</MONTH>
                 <COUNT>10</COUNT>
           </ROW>
           <ROW>
                 <DAYSOPEN>9</DAYSOPEN>
                 <REGION>MS</REGION>
                 <MONTH>2004-02</MONTH>
                 <COUNT>11</COUNT>
           </ROW>
           <ROW>
                 <DAYSOPEN>12</DAYSOPEN>
                 <REGION>PA</REGION>
                 <MONTH>2004-03</MONTH>
                 <COUNT>3</COUNT>
           </ROW>
     </DATA>
</REPORT>

I need the display on the WEB page to be :

Days Open         2004-01           2004-02           2004-03
Total
9                 0           11          0                 11
12                24          0           3                 27
15                0           14          0                 14

Region is ignored on this particular report but the data set will be used
for multiple reports. All data including months can change each time app
is
executed.

Any help you can give me would be most greatly appreciated.

Thanks

Mike

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--



--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--







<Prev in Thread] Current Thread [Next in Thread>