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 / F18686_GroupProdMuenchianWithIDs.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  3.9 KB  |  98 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ===========================================================
  3.   Styelsheet:     GroupProdMuenchianWithIDs.xsl
  4.   Category:       Grouping
  5.   Author:         David Silverlight
  6.                   HeadGeek@xmlpitstop.com
  7.   Created:        2001-05-16
  8. ================================================================ -->
  9. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  10.   <xsl:output method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />
  11.  
  12. <!--
  13. Step 1: Define the primary key to be used in the Muenchian grouping. The
  14. beautiful thing about the xsl:key  element in our example is that once we
  15. know the "region", we can easily find all of the products that match that region.
  16. The xsl:key element (different from the key() function) is defined as follows:-->
  17.   <xsl:key name="products" match="product" use="region" />
  18.  
  19.   <!-- Template for our root rule -->
  20.   <xsl:template match="/">
  21.     <html>
  22.       <head>
  23.         <title>FilteringSorting - Sorting records by parameters</title>
  24.         <style type="text/css">
  25.           H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  26.           H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  27.           .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  28.           .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  29.           .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  30.           TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
  31.           TD {COLOR: darkblue; FONT-FAMILY: Arial}
  32.           TR { background-color: beige; }
  33.           BODY { background-color: beige; }
  34.         </style>
  35.       </head>
  36.       <body>
  37.         <xsl:apply-templates />
  38.       </body>
  39.     </html>
  40.   </xsl:template>
  41.  
  42.   <!-- Template for our "products" rule -->
  43.   <xsl:template match="products">
  44.     <h2>Grouping of Products by Region, then by Product Name</h2>
  45.  
  46.     <!-- Step 2: Loop through the unique regions (the primary key) in our document.  -->
  47.     <xsl:for-each select="product[generate-id()=generate-id(key('products',region))]">
  48.       <!-- Sort Primary key by name in ascending order -->
  49.       <xsl:sort select="name" order="ascending" />
  50.       <!-- Display the region as our table header -->
  51.       <h3>
  52.         <xsl:value-of select="region" />
  53.         <xsl:text> region</xsl:text>
  54.       </h3>
  55.       <!--Display all nodes for a given region in a table-->
  56.       <table border="1">
  57.         <tr>
  58.           <th>Product Name</th>
  59.           <th>Price</th>
  60.           <th>Region</th>
  61.           <th>generate-id()</th>
  62.         </tr>
  63.         <!-- For each value in our key collection for the given region,
  64.              display values -->
  65.         <xsl:for-each select="key('products',region)">
  66.         <!--
  67.             The expression "key('products',region)" will return all of the "product"
  68.             elements from the key table whose "use=" expression defined in xsl:key
  69.             (see xsl:key at top)  evaluated to the same value as the "region" child
  70.             of the current element.  In the the example, we specified use="region".
  71.             If region has a value of "SouthWest", then all of the product elements from
  72.             the key table that contain a child element with a value of "SouthWest" will
  73.             be returned.
  74.          -->
  75.           <!--Sort our secondary key, product nodes,  by name-->
  76.           <xsl:sort select="name" />
  77.           <tr>
  78.             <td>
  79.               <xsl:value-of select="name" />
  80.             </td>
  81.             <td>
  82.               <xsl:value-of select="price" />
  83.             </td>
  84.             <td>
  85.               <xsl:value-of select="region" />
  86.             </td>
  87.             <td>
  88.               <xsl:value-of select="generate-id()" />
  89.             </td>
  90.           </tr>
  91.         </xsl:for-each>
  92.       </table>
  93.       <br />
  94.       <br />
  95.     </xsl:for-each>
  96.   </xsl:template>
  97. </xsl:stylesheet>
  98.