This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: dynamic sorting
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] dynamic sorting
- From: Jörg Heinicke <joerg dot heinicke at gmx dot de>
- Date: Sun, 4 Nov 2001 22:55:02 +0100
- References: <E6B8B86A81F8AF4482692353A032A980DA3F04@exchange.nnu.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Danny,
some ways are possible. For example the following:
XML
<table>
<row>
<name>test</name>
<age>20</age>
<city>london</city>
<country>great britain</country>
</row>
<row>
...
</row>
...
</table>
XSL
<xsl:stylesheet .....>
<!-- name is standard, pass another value to the stylesheet -->
<xsl:param name="sort">name</xsl:param>
<xsl:template match="table">
<xsl:apply-templates select="row">
<xsl:sort select="*[name() = $sort]"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="row">
<xsl:value-of select="name"/>
<xsl:value-of select="age"/>
<xsl:value-of select="city"/>
<xsl:value-of select="country"/>
</xsl:template>
</xsl:stylesheet>
For this way you need a parameter, that you pass to the stylesheet. I don't
know, in which way you start your transformation. But I know, with Cocoon 2
this version can be easily realized. What's not possible, is <xsl:sort
select="$sort"/>. Only the workaround is working.
Hope this helps,
Joerg
> Hi all,
>
> I have been searching the archives for an answer to my question, and I'm
> very surprised I didn't find anything.
>
> The problem I have relates to sorting columns in a table diplayed in the
> browser. Lets say my table has the folowing columns: Name, Age, City,
> Country, etc... I want the user to be able to click on any column name
and
> re-sort the results by his/her criteria. I have been trying to figure out
> how to do this, but it seems to me that the XSL template would have to be
> created dynamically. Can I do this kind of sorting strictly in XSL, or do
I
> have to use some kind of scripting language (JavaScript, VB Script)?
>
> Thanks in advance,
>
> Danny
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list