home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F27786_SortByDate.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  4.6 KB  |  146 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ===========================================================
  3.   Category:       XSLT
  4.   Sub-category:   xsl:sort
  5.   Author:         David Silverlight
  6.                   HeadGeek@xmlpitstop.com
  7.   Created:        2001-05-16
  8.   Description:-
  9.     This stylesheet demonstrates the use of xsl:sort by
  10.     displaying employee information sorted by date.
  11.  =============================================================== -->
  12. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  13.   <xsl:output method="html" />
  14.  
  15.   <xsl:template match="/">
  16.     <html>
  17.       <head>
  18.         <title>Stylesheet Example</title>
  19.         <style type="text/css"><![CDATA[
  20.         H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  21.         H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  22.         .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  23.         .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  24.         .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  25.         TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
  26.         TD {COLOR: darkblue; FONT-FAMILY: Arial}
  27.         TR { background-color: beige; }
  28.         BODY { background-color: beige; }
  29.         ]]></style>
  30.       </head>
  31.       <body>
  32.         <xsl:apply-templates />
  33.       </body>
  34.     </html>
  35.   </xsl:template>
  36.  
  37.   <xsl:template match="employees">
  38.     <h1>Sorting Employees by StartDate in ascending order</h1>
  39.     <table border="1">
  40.       <tr>
  41.         <th>Name</th>
  42.         <th>Department</th>
  43.         <th>Hourly Rate</th>
  44.         <th>Start Date</th>
  45.         <th>Primary Language</th>
  46.       </tr>
  47.  
  48.       <xsl:for-each select="employee">
  49.         <xsl:sort order="ascending" select="substring(startdate, 7,4)" />
  50.         <xsl:sort order="ascending" select="substring(startdate, 1,2)" />
  51.         <xsl:sort order="ascending" select="substring(startdate, 3,2)" />
  52.         <tr>
  53.           <td>
  54.             <xsl:value-of select="employeename" />
  55.           </td>
  56.           <td>
  57.             <xsl:value-of select="department" />
  58.           </td>
  59.           <td>
  60.             <xsl:value-of select="hourlyrate" />
  61.           </td>
  62.           <td>
  63.             <xsl:value-of select="startdate" />
  64.           </td>
  65.           <td>
  66.             <xsl:value-of select="primarylanguage" />
  67.           </td>
  68.         </tr>
  69.       </xsl:for-each>
  70.     </table>
  71.     <h1>Sorting Employees by StartDate in descending order</h1>
  72.     <table border="1">
  73.       <tr>
  74.         <th>Name</th>
  75.         <th>Department</th>
  76.         <th>Hourly Rate</th>
  77.         <th>Start Date</th>
  78.         <th>Primary Language</th>
  79.       </tr>
  80.       <xsl:for-each select="employee">
  81.         <xsl:sort order="descending" select="substring(startdate, 7,4)" />
  82.         <xsl:sort order="descending" select="substring(startdate, 1,2)" />
  83.         <xsl:sort order="descending" select="substring(startdate, 3,2)" />
  84.         <tr>
  85.           <td>
  86.             <xsl:value-of select="employeename" />
  87.           </td>
  88.           <td>
  89.             <xsl:value-of select="department" />
  90.           </td>
  91.           <td>
  92.             <xsl:value-of select="hourlyrate" />
  93.           </td>
  94.           <td>
  95.             <xsl:value-of select="startdate" />
  96.           </td>
  97.           <td>
  98.             <xsl:value-of select="primarylanguage" />
  99.           </td>
  100.         </tr>
  101.       </xsl:for-each>
  102.     </table>
  103.     <h1>Sorting Employees by StartDate by:
  104.     <br />
  105.     Year in ascending order
  106.     <br />
  107.     Month descending order
  108.     <br />
  109.     Day in ascending order
  110.     <br />
  111.     </h1>
  112.     <br />
  113.     <br />
  114.     <table border="1">
  115.       <tr>
  116.         <th>Name</th>
  117.         <th>Department</th>
  118.         <th>Hourly Rate</th>
  119.         <th>Start Date</th>
  120.         <th>Primary Language</th>
  121.       </tr>
  122.       <xsl:for-each select="employee">
  123.         <xsl:sort order="ascending" select="substring(startdate, 7,4)" />
  124.         <xsl:sort order="descending" select="substring(startdate, 1,2)" />
  125.         <xsl:sort order="ascending" select="substring(startdate, 3,2)" />
  126.         <tr>
  127.           <td>
  128.             <xsl:value-of select="employeename" />
  129.           </td>
  130.           <td>
  131.             <xsl:value-of select="department" />
  132.           </td>
  133.           <td>
  134.             <xsl:value-of select="hourlyrate" />
  135.           </td>
  136.           <td>
  137.             <xsl:value-of select="startdate" />
  138.           </td>
  139.           <td>
  140.             <xsl:value-of select="primarylanguage" />
  141.           </td>
  142.         </tr>
  143.       </xsl:for-each>
  144.     </table>
  145.   </xsl:template>
  146. </xsl:stylesheet>