[xsl] Grouping by Node & Node Attributr

Subject: [xsl] Grouping by Node & Node Attributr
From: jeb501@xxxxxxxxxxxxxxx
Date: Mon, 30 Oct 2006 12:01:50 +0530
Hi all,

WIth following XML & XSL files, after transformation i get an html

file as below.

XML :

  <?xml version="1.0" ?>
    + <sum>
      - <record>
          <mon cat="OT">Sep2005</mon>
          <qty>3.00</qty>
          <weight>15.66000</weight>
      </record>
      - <record>
          <mon cat="1X">Sep2005</mon>
          <qty>12.00</qty>
          <weight>36.12000</weight>
      </record>
      - <record>
          <mon cat="OT">Sep2005</mon>
          <qty>2.00</qty>
          <weight>39.90000</weight>
      </record>
      - <record>
          <mon cat="1X">Sep2005</mon>
          <qty>16.00</qty>
          <weight>7.05600</weight>
      </record>
      - <record>
          <mon cat="1X">Sep2005</mon>
          <qty>32.00</qty>
          <weight>12.48000</weight>
      </record>
    </sum>


  XSL :

  <?xml version="1.0" encoding="ISO-8859-1" ?>
    - <xsl:stylesheet version="1.0" xmlns:xsl="
    http://www.w3.org/1999/XSL/Transform";>
      - <xsl:template match="/">
        - <html>
          - <body>
            - <table border="1" cellpadding="4" cellspacing="0">
              - <tr bgcolor="#9acd32">
                  <th rowspan="2">Month</th>
                  <th rowspan="2">Cat</th>
                  <th colspan="2">P Qty</th>
              </tr>
              - <tr bgcolor="#9acd32">
                  <th>Qty</th>
                  <th>Value</th>
              </tr>
              - <xsl:for-each select="sum/record">
                - <tr>
                  - <td>
                      <xsl:value-of select="mon" />
                  </td>
                  - <td>
                      <xsl:value-of select="mon/@cat" />
                  </td>
                  - <td align="right">
                      <xsl:value-of select="qty" />
                  </td>
                  - <td align="right">
                      <xsl:value-of select="weight" />
                  </td>
                </tr>
              </xsl:for-each>
            </table>
          </body>
        </html>
      </xsl:template>
    </xsl:stylesheet>

  HTML actual Output :

Current Thread