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

RE: XML grouping/sorting question - displaying a matri

Subject: RE: XML grouping/sorting question - displaying a matrix
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Tue, 30 Mar 2004 10:26:56 +0300
30 matri
Hi,

> Finally, I would ultimately like to sort the columns in the 
> above matrix by
> element count so that the elements which appear most are in the first
> columns, though I haven't found a way to do this:
> 
> ID        X    C    B    Y
> 0001      *         *
> 0002      *              *
> 0003      *    *
> 0004      *    *

  <xsl:key name="test-by-name" match="test" use="name"/>
  <xsl:template match="records">
    <html>
      <body>
        <table>
          <thead>
            <tr>
              <th>ID</th>
              <xsl:for-each select="record/test[count(. | key('test-by-name', name)[1]) = 1]">
                <xsl:sort select="count(key('test-by-name', name))" data-type="number" order="descending"/>
                <th>
                  <xsl:value-of select="name" />
                </th>
              </xsl:for-each>
            </tr>
          </thead>
          <tbody>
            <xsl:for-each select="record/test">
              <xsl:variable name="current" select="name"/>
              <tr>
                <th>
                  <xsl:value-of select="@id"/>
                </th>
                <xsl:for-each select="../../record/test[count(. | key('test-by-name', name)[1]) = 1]">
                  <xsl:sort select="count(key('test-by-name', name))" data-type="number" order="descending"/>
                  <td>
                    <xsl:if test="name = $current">*</xsl:if>
                  </td>
                </xsl:for-each>
              </tr>
            </xsl:for-each>
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>

or, if can use ext:node-set

  <xsl:template match="records" xmlns:exsl="http://exslt.org/common">
    <html>
      <body>
        <table>
          <xsl:variable name="columns-rtf">
            <xsl:for-each select="record/test[count(. | key('test-by-name', name)[1]) = 1]">
              <xsl:sort select="count(key('test-by-name', name))" data-type="number" order="descending"/>
              <xsl:copy-of select="name" />
            </xsl:for-each>
          </xsl:variable>
          <xsl:variable name="columns" select="exsl:node-set($columns-rtf)/name"/>
          <thead>
            <tr>
              <th>ID</th>
              <xsl:for-each select="$columns">
                <th>
                  <xsl:value-of select="." />
                </th>
              </xsl:for-each>
            </tr>
          </thead>
          <tbody>
            <xsl:for-each select="record/test">
              <xsl:variable name="current" select="name"/>
              <tr>
                <th>
                  <xsl:value-of select="@id"/>
                </th>
                <xsl:for-each select="$columns">
                  <td>
                    <xsl:if test=". = $current">*</xsl:if>
                  </td>
                </xsl:for-each>
              </tr>
            </xsl:for-each>
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>

or you could create a space separated list of column names and go through that with a recursive template.

Cheers,

Jarno

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.