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 of elements

Status
Not open for further replies.

chantey

Instructor
Jan 28, 2004
11
GB
Hi guys,

Im still fairly new to XML and need help on the following problem.

I know how to sort elements alphabetically using my XSL stylesheet. All I do is use <xsl:sort> in the template.

I want some buttons or links on my XML page that will dynamically change the sort order.

For example, if i have the following data

Book A (2004)
Book B (2002)

Given by

<books>
<title>Book A
<year>2004</year>
</title>
<title>Book B
<year>2002</year></title>
</books>

I want a button that says 'sort by title' which when clicked, will sort the list by title, and a button that says 'sort by year' which when clicked, orders the list by year.

Is this possible?
Any help would be appreciated.

Thanks
 
It is possible: you can put <xsl:param name ="sortfield"/>
in your stylesheet, and use it in <xsl:sort select="*[name()=$sortfield]"/>
How you pass parameters to your XSLprocessor depend a bit on the situation.
However, this way you parse the whole page again.
I can imagine someone invented a trick do do sorting in javascript, so without parsing the whole page again, - but I wouldn't know how...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top