Output Filtering << Data Sorting >>
The next ability of XSLT is sorting. That is putting a list of data into alphabetical order. This can be used on its own or in combination with the filtering methods discussed on the previous page.

Imagine a much larger list of movies in our XML file. (I am really lazy and don't want to type out a bunch more, so I am relying on your imagination here.). To sort through these and prepare them using normal HTML coding would probably take a good part of the day. Using XSLT, it takes one command line.

The sort command will alphabetically sort the list according to the tag specified.

We will add the sort command to adjust the records according to the movie titles. The sort command is placed within the for-each command area.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:template match="/">


<table border="1">
<xsl:for-each select="list_of_movies/movie">
<xsl:sort select="title"/>
<td> <xsl:value-of select="title"/> </td>
<td> <xsl:value-of select="age_group"/> </td>
<td> <xsl:value-of select="comments"/> </td>



You can now view the XML page... XML Example 8
Output Filtering << Data Sorting >>

Advertise in the banner along the top, Click here!

Valid XHTML 1.0 Transitional Valid CSS! Text Link Ads