home *** CD-ROM | disk | FTP | other *** search
Wrap
<?xml version="1.0" encoding="utf-8"?> <!-- =========================================================== Category: XSLT Sub-category: xsl:sort Author: David Silverlight HeadGeek@xmlpitstop.com Created: 2001-05-16 Description:- This stylesheet demonstrates the use of xsl:sort by displaying employee information sorted by amount. =============================================================== --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" /> <xsl:template match="/"> <html> <head> <title>Stylesheet Example</title> <style type="text/css"><![CDATA[ H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;} H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;} .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;} .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;} .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;} TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;} TD {COLOR: darkblue; FONT-FAMILY: Arial} TR { background-color: beige; } BODY { background-color: beige; } ]]></style> </head> <body> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="employees"> <h1>Sorting Employees by Hourly Rate in ascending order</h1> <table border="1"> <tr> <th>Name</th> <th>Department</th> <th>Hourly Rate</th> <th>Start Date</th> <th>Primary Language</th> </tr> <xsl:for-each select="employee"> <xsl:sort order="ascending" select="hourlyrate" data-type="number" /> <tr> <td> <xsl:value-of select="employeename" /> </td> <td> <xsl:value-of select="department" /> </td> <td> <xsl:value-of select="hourlyrate" /> </td> <td> <xsl:value-of select="startdate" /> </td> <td> <xsl:value-of select="primarylanguage" /> </td> </tr> </xsl:for-each> </table> <br /> <br /> <h1>Sorting Employees by HourlyRate in descending order</h1> <table border="1"> <tr> <th>Name</th> <th>Department</th> <th>Hourly Rate</th> <th>Start Date</th> <th>Primary Language</th> </tr> <xsl:for-each select="employee"> <xsl:sort order="descending" select="hourlyrate" data-type="number" /> <tr> <td> <xsl:value-of select="employeename" /> </td> <td> <xsl:value-of select="department" /> </td> <td> <xsl:value-of select="hourlyrate" /> </td> <td> <xsl:value-of select="startdate" /> </td> <td> <xsl:value-of select="primarylanguage" /> </td> </tr> </xsl:for-each> </table> <br /> <h1>Incorrect Sorting of Employees by HourlyRate</h1> <span class="subhead">This example demonstrates the how omitting the data-type attribute will cause your numbers to be sorted alphabetically, rather than by their numeric value (yes, this is bad)</span> <br /> <table border="1"> <tr> <th>Name</th> <th>Department</th> <th>Hourly Rate</th> <th>Start Date</th> <th>Primary Language</th> </tr> <xsl:for-each select="employee"> <xsl:sort order="ascending" select="hourlyrate" /> <tr> <td> <xsl:value-of select="employeename" /> </td> <td> <xsl:value-of select="department" /> </td> <td> <xsl:value-of select="hourlyrate" /> </td> <td> <xsl:value-of select="startdate" /> </td> <td> <xsl:value-of select="primarylanguage" /> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>