Update sorting javascript

Discussion in 'XML' started by reclusive monkey, Aug 4, 2005.

  1. I copied the following example from MSDN, and it works nicely. However,
    I want to combine it with another technique I discovered on the IBM
    Developer site. However, the first method relies upon Micorsoft's old
    xmlns:xsl="http://www.w3.org/TR/WD-xsl" namespace and "order-by" but
    the other technique uses position(), which won't work with
    xmlns:xsl="http://www.w3.org/TR/WD-xsl". Can anyone help me with
    regards to altering the javascript at the top to work with xsl:sort
    rather than order-by? Thanks. My current XSLT is this;

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
    <html>
    <head>
    <title>SCSD Finance Department - Cost Centres</title>
    <link rel="stylesheet" href="IntranetPrintStyle.css" type="text/css"
    media="print" />
    <link rel="stylesheet" href="IntranetStyle.css" type="text/css"
    media="screen" />
    </head>
    <body>
    <SCRIPT><xsl:comment><![CDATA[
    function sort(field)
    {
    sortField.value = field;
    <!-- set cursor to watch here? -->
    listing.innerHTML = source.documentElement.transformNode(stylesheet);
    }
    ]]></xsl:comment></SCRIPT>
    <SCRIPT for="window" event="onload"><xsl:comment><![CDATA[
    stylesheet = document.XSLDocument;
    source = document.XMLDocument;
    sortField = document.XSLDocument.selectSingleNode("//@order-by");
    ]]></xsl:comment></SCRIPT>
    <div id="container">
    <div id="header">
    <a name="Top"></a>
    <h1>SCSD Finance Department</h1>
    <h2>Cost Centres</h2>
    </div>
    <div class="content">
    <div class="content_header">
    <span>Click on a heading to sort</span>
    </div>
    <div class="content_body">
    <p>
    <div id="listing">
    <xsl:apply-templates select="dataroot"/>
    </div>
    </p>
    </div>
    <div class="content_footer">
    <span><a href="#top">Back to top</a></span>
    </div>
    </div>
    </div>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="dataroot">
    <table width="99%" align="center">
    <thead>
    <th width="10%"><div onClick="sort('CostCentreID')"><a>Cost
    Centre</a></div></th>
    <th width="40%"><div
    onClick="sort('CostCentreDescription')">Description</div></th>
    <th width="25%"><div onClick="sort('BM')">Budget Manager</div></th>
    <th width="25%"><div onClick="sort('FMO')">F.M.O.</div></th>
    </thead>
    <xsl:for-each select="tblCostCentresXML" order-by="CostCentreID">
    <tr>
    <td><xsl:value-of select="CostCentreID" /></td>
    <td><xsl:value-of select="CostCentreDescription" /></td>
    <td><xsl:value-of select="BM" /></td>
    <td><xsl:value-of select="FMO" /></td>
    </tr>
    </xsl:for-each>
    </table>
    </xsl:template>
    </xsl:stylesheet>

    But I want to be able to change the bottom template to something along
    the lines of this (which I have working without the javascript sorting)
    so that I can style alternate lines differently for legibility;

    <xsl:template match="tblCostCentresXML[position() mod 2 = 1]">
    <tr class="odd">

    and then

    <xsl:template match="tblCostCentresXML">
    <tr class="even">

    However, When I apply the
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" namespace to correct
    the position problem, I get the "Can't use order-by" problem. I know
    its sortField = document.XSLDocument.selectSingleNode("//@order-by");
    that needs changing, but I am a bear of very little brain and
    JavaScript bothers me. I am sure an XML/Javascript whizz will know the
    answer...
    reclusive monkey, Aug 4, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Dalke

    Update the sorting mini-howto

    Andrew Dalke, Nov 29, 2005, in forum: Python
    Replies:
    0
    Views:
    301
    Andrew Dalke
    Nov 29, 2005
  2. Replies:
    2
    Views:
    1,407
    James Kanze
    Jul 6, 2010
  3. Jason
    Replies:
    0
    Views:
    372
    Jason
    Oct 4, 2006
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    465
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    142
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page