Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using XSLT parameters in a browser transform

Reply
Thread Tools

Using XSLT parameters in a browser transform

 
 
David
Guest
Posts: n/a
 
      04-02-2004
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput 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?
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-03-2004


David wrote:

> 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/x...TableSort.html
but note that the document is an HTML document that does all
transformations with scripting. And I haven't used <xslaram> 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.
--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nokogiri : XSLT Transform passing parameters Une Bévue Ruby 1 01-29-2012 03:15 PM
Transform XML to XML using XSLT adi XML 1 06-06-2006 01:06 AM
Transform XML string using XSLT file Isambella via DotNetMonster.com ASP .Net 4 08-02-2005 07:19 AM
blocking I/O with javax.xml.parsers.DocumentBuilder.parse() and javax.xml.transform.Transformer.transform() jazzdman@gmail.com Java 1 03-27-2005 06:56 AM
Transform XML using XSLT based on element position Igor XML 1 07-20-2003 08:16 PM



Advertisments