473,387 Members | 1,486 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,387 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 1143

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.