View Full Version : Clickable Sort Links

05-28-2009, 07:48 PM
I have created an XSL sheet that formats an XML feed into 3 separate tables... the default sorting is done on the 'name' column

I would like to make the headings clickable links so that I can sort each table by the column I choose... I've done some googling but haven't really found what I'm looking for

I would think this would be easily done by using query string values in the links, but, I couldn't find any documentation on how to pass query string values to XSL


05-28-2009, 08:52 PM
here is one of the blocks of XSL that dumps the rows of one table

<xsl:for-each select="channel/item[status='Active']">
<xsl:attribute name="bgcolor">
<xsl:value-of select="color"/>
<td width="16">
<xsl:attribute name="src">
<xsl:value-of select="icon"/>
<td width="180">
<xsl:attribute name="href">
<xsl:value-of select="link"/>
<xsl:value-of select="name"/>
<td align="center" width="45"><xsl:value-of select="cnt"/></td>
<td align="right" width="90"><xsl:value-of select="fm"/></td>
<td align="right" width="140"><xsl:value-of select="int"/></td>
<td align="right" width="140"></td>
<td align="right" width="70"><xsl:value-of select="run"/> Days</td>

id like to be able to sort on:

name, cnt, fm, int, run

05-28-2009, 09:22 PM
so if I click on

<xsl:attribute name="href"><![CDATA[?table=active&sort=run]]></xsl:attribute>Run

i can pass the value of 'sort' to:

<xsl:sort select="name"/>

and my table would b e sorted by the run column

Alex Vincent
05-29-2009, 02:04 AM
I don't think XSL has any concept of query strings, at least when run inside the browser. You'll need some script support - either server-side or JavaScript.

05-29-2009, 02:40 AM
I did find this tutorial:


which says you just have to define an xsl:param to match the name of the query string variable but I can't seem to get this working


First thing we're going to do is to add dynamic sorting. This works using the XSL-Element <xsl:sort /> in combination with a variable. We'll insert a parameter into our XSL on top and reform the th-content in two of our collumns.

<th><a href="?smode=postcode">postcode</a></th>
<th><a href="?smode=city">city</a></th>

So now the variable “smode” will be passed to the processor. Buit we have to introduce it within the XSL as well. So within the first template we'll declare it with this line of code:

<xsl:param select="$smode"/>

i then tried to write it out by using:

<xsl:value-of select="$smode"/>

and it displays nothing

Note: I used

<xsl:param select="$sort"/>
<xsl:value-of select="$sort"/>

any ideas?