Re: [xsl] HTML sortable columns

Subject: Re: [xsl] HTML sortable columns
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 21 Oct 2004 11:32:49 -0400
John,

To amplify what Jarno is saying...

At 10:28 AM 10/21/2004, you wrote:
Thanks. The developer is currently planning to generate multiple HTML files with pre-sorted, which seems a little silly to me.

It is a little silly, but it works as a "poor man's solution" and has the virtue of requiring no dynamic behavior on either client or server once the HTML is generated. If your XSLT is running dynamically on the server, this advantage amounts to one only of performance (since all the HTML is pre-generated). It's a viable way to go especially if your data doesn't change really quickly.


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?

Yes. The sort criterion can be switched by a value passed in at runtime to the transformation. See the indexes on http://sonneteer.xmlshoestring.com for an example -- hitting a different sort order calls the transformation with a parameter that switches not only the value on which things are sorted (author, title, first line or rhyme scheme, which is itself generated dynamically), but also the template set that is used for the listings themselves (so listings in the "by author" sort appear differently from listings in the "by title" sort, etc.)


(Bruce D, if you're reading this -- this is also effectively what you are trying to do, although in your case sorting doesn't come into it. The trick here is modes, which don't prove to be too cumbersome since there aren't many templates in any of the four modes, and it's unlikely I'll ever want to add a new sort order. Otherwise I might be doing the stylesheet layering I've been recommending to you.)

But I agree with Jarno that in simpler cases, the sorting would be better performed client-side with script delivered in the HTML. There are actually a couple of ways to do this: the Java|ECMAscript could either do the sorting itself, or it could fake it by hiding and exposing entire pre-sorted lists all generated on the server and passed to the client. The tradeoffs here involve the complexity of your functional requirements for the sort and the size of the dataset.

I hope this helps,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread