![]() | |
Displaying XML Files Sorting the Results Using XSL FileIn the Previous Example we have seen that Results are displayed Linearly one Book after another in the order they have been declared in the XML file. Now we want these Books to be Displayed Sorted by the Authors Name. Here's one of the Best Advantages that XML and XSL provide. Here when user wants to view data sorted by a different field, the we don't have to make a request again to the Database. The same XML file can be displayed sorted by a different field. Here's the Syntax for
Sorting the Data, Considering the same XML file which has the List of all Books declared
in the previous page, now we want to show the List of Books sorted by Authors
Name,
Note that here we have added a new parameter called order-by="+ AUTHOR". The "+" symbol indicates order in ascending order. For Descending order use "-" sign. Here we asked the XSL file to sort the List of Books based on Authors name. So finally in the Output HTML files, all the Books will be shown in the Table Format, with Books sorted by Authors Name. If the Sort Parameter is a Number, then you can also you the <xsl:sort /> tag for specifying the sorting order. Here's the Syntax for using the Sort Tag.
In the above XSL file "xsl:sort" parameter acts a extra parameter to the "xsl:for-each" tag and helps in sorting the data.
|