<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" />
<!--
	Copyright (c) 2002 Kenneth B. Sall. All Rights Reserved. 
	This code may not be copied, modified, or duplicated in any manner 
	without written consent from the author at ken@sall.net. 
-->
 
<xsl:param name="label">XML.gov Demo: Brainstorming XML to Average Sort</xsl:param>

<xsl:template match="/">
   <html>  
     <head>
       <title><xsl:value-of select="$label" /></title>
     </head>
     <body>
       <h2 align="center"><xsl:value-of select="$label" /></h2>
       
        <table cellpadding="5"  border="2" align="center" 
		style="font-family:Arial,sans-serif; font-size:10pt">
        <tbody>
           <tr style="color:black; background-color:#e9d6e7">
             <th>id</th>
             <th>Idea Description</th>
             <th><a href="tableLow.html">Lo</a></th>
             <th><a href="tableMedium.html">Md</a></th>
             <th><a href="tableHigh.html">Hi</a></th>
             <th><a href="tableDefault.html">Wghtd Total</a></th>
             <th>Votes</th>
             <th style="border:thin red solid; color:black; background-color:white">Avr</th>
             <th><a href="tableLead.html">Lead</a></th> <!-- TBD Volunteers -->
             <th>Volunteers</th> <!-- TBD Volunteers -->
             <th>Project</th>
            </tr>

        <xsl:apply-templates />

	<!-- Handle summary data, stored in root element. -->
         <tr style="font-weight:bold; color:black; background-color:#e9d6e7">
	    <td colspan="2" align="center">Averages</td>
	    <td>&#xA0;</td>
	    <td>&#xA0;</td>
	    <td>&#xA0;</td>
	    <td align="center"><xsl:value-of select="/Brainstorming/@avrWeightedTotalScore" /></td>
	    <td align="center"><xsl:value-of select="/Brainstorming/@avrTotalVotes" /></td>
	    <td align="center"><xsl:value-of select="/Brainstorming/@avrAverage" /></td>
	    <td>&#xA0;</td>
	    <td>&#xA0;</td>
	    <td>&#xA0;</td>
         </tr>

         </tbody>
       </table>

    <p style="font-weight:bold; text-align:center; font-family:Arial">Demo 
created by <a href="mailto:ken@sall.net">Ken Sall</a>, 
<a href="http://kensall.com">XML Consultant</a>.</p>

<p style="text-align:center; font-family:Arial">Based on
<a href="http://xml.gov/documents/in_progress/brainstormranking.htm">XML.Gov 
Ranking of Brainstorming Ideas</a> page.
</p>
             
    </body>
   </html>
</xsl:template>

<!-- Special sort -->
<xsl:template match="Brainstorming"> 
    <xsl:for-each select="Idea">
       <xsl:sort data-type="number" order="descending"
		select="Average" /> 
       <xsl:apply-templates />
    </xsl:for-each>
</xsl:template>


<xsl:template match="Average"> 

  <!-- Idea node is *parent* of our sort key -->
  <xsl:variable name="ideaNode" select=".." />

  <xsl:variable name="rowColor">
    <xsl:choose> 
      <xsl:when test="$ideaNode/@origID mod 2" >#ffffff</xsl:when>
      <xsl:otherwise>#eeeeee</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <tr style="color:black; background-color:{$rowColor}">
    <td><xsl:value-of select="$ideaNode/@origID" /></td>
    <td style="font-weight:bold"><xsl:value-of select="$ideaNode/Description" /></td>
    <td align="center"><xsl:value-of select="$ideaNode/Rankings/Low" /></td>
    <td align="center"><xsl:value-of select="$ideaNode/Rankings/Medium" /></td>
    <td align="center"><xsl:value-of select="$ideaNode/Rankings/High" /></td>
    <td align="center"><xsl:value-of select="$ideaNode/WeightedTotalScore" /></td>
    <td align="center"><xsl:value-of select="$ideaNode/TotalVotes" /></td>
    <td align="center"><xsl:value-of select="$ideaNode/Average" /></td>
    <td><xsl:value-of select="$ideaNode/FocusGroup/Lead/Last" /></td>
    <td><xsl:value-of select="$ideaNode/FocusGroup/Volunteer[1]/Last" /></td>
    <td><xsl:value-of select="$ideaNode/ProjectName" /></td>
  </tr>
</xsl:template>

<xsl:template match="text()" /> <!-- swallow other text -->

</xsl:stylesheet>
