Using XSLT parameters in a browser transform

Discussion in 'XML' started by David, Apr 2, 2004.

  1. David

    David Guest

    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?
     
    David, Apr 2, 2004
    #1
    1. Advertising

  2. 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/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.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Apr 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Isambella  via DotNetMonster.com

    Transform XML string using XSLT file

    Isambella via DotNetMonster.com, Aug 1, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    9,805
    Isambella via DotNetMonster.com
    Aug 2, 2005
  2. Igor
    Replies:
    1
    Views:
    5,028
    Dimitre Novatchev
    Jul 20, 2003
  3. adi
    Replies:
    1
    Views:
    31,742
    Joe Kesselman
    Jun 6, 2006
  4. Water Cooler v2

    Transform an XML file using XSLT

    Water Cooler v2, Aug 1, 2006, in forum: XML
    Replies:
    1
    Views:
    767
    Joe Kesselman
    Aug 2, 2006
  5. Une Bévue
    Replies:
    1
    Views:
    1,145
    Une Bévue
    Jan 29, 2012
Loading...

Share This Page