473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 1141

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gareth Gale | last post by:
I'm trying to implement a way of allowing a user to sort a HTML table via Javascript on the client. I've seen lots of samples where single column sorting (asc or desc) is shown, but I'd like nested...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
2
by: Richard Cornford | last post by:
Anyone who has taken a look at the online FAQ today may have noticed that I have updated it. The majority of the changes are the updating of broken links and the implementation of that extensive...
2
by: Alan Searle | last post by:
I find that I can display structured data very nicely using XML with an XSL template. As an extra 'goodie', I would like to give users the ability to sort that data (for example with a button...
0
by: Andrew Dalke | last post by:
Years ago I wrote the Sorting mini-howto, currently at http://www.amk.ca/python/howto/sorting/sorting.html I've had various people thank me for that, in person and through email. It's...
6
by: bcochofel | last post by:
I'm using xsl to list an xml file that contains something like: sites, tag and weight. I'm listing this in a table with the following titles: | URL | TAG | WEIGHT (each title his a link) What...
1
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID"...
2
by: rrowles2000 | last post by:
Hi, I have four chuncks of html and I'm trying to sort them. see this link. Basically the sort works for alphabetic sort but not for numerics. Any ideas very welcome? I just can't see what I'm...
2
by: cluce | last post by:
i have a table sorting feature on my website that works everywhere else except in firefox. but the example code does work in firefox. this has me stumped. The problem is the links in the table...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.