471,354 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Update sorting javascript

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')">Descriptio n</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...

Aug 4 '05 #1
0 1079

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Gareth Gale | last post: by
22 posts views Thread by mike | last post: by
2 posts views Thread by Richard Cornford | last post: by
2 posts views Thread by Alan Searle | last post: by
reply views Thread by Andrew Dalke | last post: by
6 posts views Thread by bcochofel | last post: by
1 post views Thread by Evan M. | last post: by
2 posts views Thread by rrowles2000 | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.