Using XSLT parameters in a browser transform

David (archive)

Usenet Archive
Joined
Jan 7, 2000
Messages
927
Reaction score
0
I would like to be able to re-sort data in an HTML table on the without returning to the server. It seems like an XSLT should be able to accomplish this, but I can't find enough information...

I have am XML file generated on the server that looks something like this:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="search.xsl"?>
<AlbumSearch version="3.0" time="02Apr04 10:54:31 EST"> <SearchResults field="artist" string="Barenaked Ladies"> <Album artist="Barenaked Ladies" title="Born On A Pirate Ship" released="1996"/> <Album artist="Barenaked Ladies" title="Gordon" released="1992"/> <Album artist="Barenaked Ladies" title="Maroon" released="2000"/> <Album artist="Barenaked Ladies" title="Maybe You Should Drive" released="1994"/> </SearchResults> </SalesSearch>

Here's my stylesheet:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:eek:utput method="html"/>

<xsl:template match="/AlbumSearch">
<html>
<body>
<xsl:for-each select="SearchResults">
<table border="1">
<thead>
<tr>
<th>Artist</th>
<th>Title</th>
<th>Release Date</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates>
<xsl:sort select="@artist"/>
</xsl:apply-templates>
</tbody>
</table>
</xsl:for-each>

</body>
</html>
</xsl:template>

<xsl:template match="Album">
<tr>
<td><xsl:value-of select="@artist"/></td>
<td><xsl:value-of select="@title"/></td>
<td><xsl:value-of select="@released"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>

The idea is to transform this into HTML on the client, placing the album list into an HTML table. What I'd like to accomplish is to include links or buttons in each column header that would allow the user to click on them and resort the album list by that column without round-tripping to the server. The stylesheet I currently have obvisouly hardcodes the sort order; I'd like to determine the sort order based on the user's selection.

Anyone have any ideas? Would using a little bit of script to kick off a new transform work, passing a parameter based on which column the user kicked?
Where can I find an example?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
David said:
I would like to be able to re-sort data in an HTML table on the without returning to the server. It seems like an XSLT should be able to accomplish this, but I can't find enough information...

I have an example at
http://home.arcor.de/martin.honnen/xslt/tableSorting/tdf-winnersXSLTTableSort.html but note that the document is an HTML document that does all transformations with scripting. And I haven't used <xsl:param> elements as I think that you need to manipulate the DOM of the stylesheet if you want to sort on different elements or attributes, a param would only help to change the sort order (e.g. ascending vs. descending). The example has been tested to work with IE6, Netscape 7.1, Mozilla 1.1, Firefox 0.8.

Of course there are different approaches possible, for instance you could (as you have in your example) let the browser do the initial transformation with <?xsl-stylesheet?> and then use script only to sort the table. And for sorting there you could not even use XSLT but use DOM scripting to perform the sort.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top