Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic sorting in xml/xsl

Status
Not open for further replies.

bluebytez

Programmer
Dec 20, 2001
39
MY
Hi,
How can I implement dynamic sorting in xml/xsl ? ( ie. click on the column header and the table will be sorted according to the table ? )
 
I have been trying to figure this one out myself. It seems like it should be pretty easy, but it's a lot harder than it looks. Every example I've seen using the old working-draft namespace and I need to use the new one.

Endbringer
 
well the way i did it, and maybe not the way you are trying to do it, is to pass a param back to the xsl page identifying the local-name of the element you want to sort on.

given:

<tablexml>
<headers>
<column-header sort-node=&quot;name&quot;/>
...
<column-header sort-node=&quot;address&quot; />
</headers>
<data>
<row><name/><address/>...</row>
<row>...</row>
</data>
</tablexml>

your xsl will look like a bit like this:

...
<xsl:template match=&quot;row&quot; ... >
<xsl:param name=&quot;$mylocalname&quot; />
...
<xsl:apply-template select=&quot;*&quot;>
<xsl:sort select=&quot;$mylocalname&quot;/>
</xsl:apply-template>

</xsl:template>
...

and then you need to pass in the local-name of the node that relates to the column in the table to the xsl stylesheet in the onclick function of the <td> tag.

the part of the xsl that generates the table headers will look a bit like this:

<xsl:template match=&quot;column-header&quot;... >
<tr>
<xsl:element name=&quot;td&quot;>
<xsl:attribute name=&quot;onclick&quot;>
<xsl:text>
document.location.href=&quot;./myscript.blah?sortname='
</xsl:text>
<xsl:value-of select=&quot;@sort-node&quot;/>
<xsl:text>';&quot;</xsl:text>
</xsl:attribute>
<xsl:value-of select=&quot;text()&quot;/>
</xsl:element>
</xsl:template>

.. and when you generate the page with &quot;myscript.blah&quot; pass the value &quot;sortname&quot; to the xsl stylesheet as a parameter, which should then sort the results of the data correctly.

ps i have not tested any of this, but feel free to ask if you have problems.

hope that helps.
 
probably not what you want, but just in case i thought i'd mention it anyway.

if your implementation is solely html, then you might want to consider using a client side javascript to do the work for you...write your table out and the javascript can rearrange it using the html dom

check out for a quick sample mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top