Re: [xsl] HTML sortable columns

Subject: Re: [xsl] HTML sortable columns
From: John <john-xsl-list@xxxxxxxx>
Date: Thu, 21 Oct 2004 07:28:49 -0700
Thanks. The developer is currently planning to generate multiple HTML files with pre-sorted, which seems a little silly to me. I was hoping to suggest XML/XSL as an alternative, as I would really expect it to be possible with these tools. For instance, assuming the following simplified XML:

<table>
 <row>
     <column sortid="1">value</column>
     <column sortid="2">value</column>
 </row>
 <row>
     <column sortid="1">value</column>
     <column sortid="2">value</column>
 </row>
</table>

If the application server passes a valid sortid value, shouldn't it be possible to have multiple sorts in the XSL, or sort using the parameter as criteria? What I type below is just "pseudo code" as this really isn't my problem and I don't have time to test. Sorry for my for-each but I'm not yet good with apply-templates.

<xsl:param name="sortid" select="'1'" />

<xsl:for-each select="/table/row/column[@sortid=$sortid"]>
 <xsl:sort select="text()" />
 <xsl:call-template name="row" />
</xsl:for-each>

The row template would need to know about the column's siblings. Seems possible, what am I missing?

Thanks again,

-John

Jarno.Elovirta@xxxxxxxxx wrote:

Hi,



I'm actually asking this question "for a friend".

In the generic context of some application/webserver, does anyone have any XSL suggestions or examples for presenting a table (generated from XML data) with headers that let the users sort the data by different columns?



The solution is partially out of scope for XSLT. Your friend can implement sorting by retransforming the source and passing the sort key name as a parameter, but they need to write non-XSLT code to handle the retransform requests, be it e.g. Java at server-side and ECMAScript at browser-side.


Cheers,

Jarno - VNV Nation: Honour (Juno version)

Current Thread