<?xml version='1.0'?>
<!DOCTYPE xsl:stylesheet
 [ <!ENTITY xnbsp "&amp;nbsp;">
   <!ENTITY nbsp "&#160;"> ]>
<xsl:stylesheet version="1.0"
                xmlns="http://www.w3.org/TR/xhtml1/transitional"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- Project Notebook XSLT translator stylesheet.

     Project Documents page - generates projdocs.html

     This is a *very rough* first cut at translating the Project Notebook
     XML document into HTML automatically.
-->

<xsl:output method="html" indent="yes" media-type="text/html"/>

<xsl:include href="shared.xsl" /> <!-- shared definitions for I/S Project -->

<xsl:template match="/project">
    <HTML xmlns="http://www.w3.org/TR/xhtml1/transitional">

    <xsl:call-template name="head-element">
        <xsl:with-param name="title"><xsl:value-of select="@name"/> -- Documents</xsl:with-param>
    </xsl:call-template>

    <xsl:element name="BODY" use-attribute-sets="body-attrs">

    <xsl:call-template name="title-block">
        <xsl:with-param name="title">Project Documents</xsl:with-param>
        <xsl:with-param name="subtitle"><xsl:value-of select="/project/@name"/></xsl:with-param>
    </xsl:call-template>

    <TABLE BORDER="0" CELLSPACING="3" CELLPADDING="3" WIDTH="100%">

       <!-- TOC row, links to category sections
            ugh, hard-coded for categories: basic, communication, output, other
            ..but restructuring the XML into a hierarchy of elements would
            be less convenient for the writers, and this is good XSLT exercise.
        -->
       <TR>
         <TH WIDTH="141" ALIGN="right">On this page:</TH>
         <TD>
           <xsl:if test="document[@category='basic']"><A href="#basic">Basic Documents</A></xsl:if>
           <xsl:if test="document[@category='communication']"> | <A href="#communication">Communications</A></xsl:if>
           <xsl:if test="document[@category='output']"> | <A href="#output">Project Outputs</A></xsl:if>
           <xsl:if test="document[@category='other']"> | <A href="#other">Other Documents</A></xsl:if>
         </TD>
       </TR>


       <!-- Table row with nothing but a horizontal rule -->
       <TR><TD COLSPAN="2"><HR/></TD></TR>

       <xsl:call-template name="title-row"/>

       <!--
            ugh, once again hard-coded for categories:
                basic, communication, output, other
            ..but restructuring the XML into a hierarchy of elements would
            be less convenient for the writers, and this is good XSLT exercise.
        -->
         <xsl:call-template name="docs-section">
             <xsl:with-param name="category">basic</xsl:with-param>
             <xsl:with-param name="label">Basic Project Components</xsl:with-param>
         </xsl:call-template>
         <xsl:call-template name="docs-section">
             <xsl:with-param name="category">communication</xsl:with-param>
             <xsl:with-param name="label">Project Communications</xsl:with-param>
         </xsl:call-template>
         <xsl:call-template name="docs-section">
             <xsl:with-param name="category">output</xsl:with-param>
             <xsl:with-param name="label">Project Output Documents</xsl:with-param>
         </xsl:call-template>
         <xsl:call-template name="docs-section">
             <xsl:with-param name="category">other</xsl:with-param>
             <xsl:with-param name="label">Other Kinds of Documents</xsl:with-param>
         </xsl:call-template>
    </TABLE>
         
    <xsl:call-template name="trailer-block"/>

    </xsl:element> <!-- /body -->
    </HTML>
</xsl:template>

<!-- renders a table row for given category of documents -->
<xsl:template name="docs-section">
    <xsl:param name="category"/>
    <xsl:param name="label"/>
    <!-- only bother to emit the item if there are any docs in category -->
    <xsl:if test="/project/document[@category = $category]">
       <!-- Table row with nothing but a horizontal rule -->
       <TR><TD COLSPAN="2"><P><HR/></P></TD></TR>

       <TR>
         <A name="{$category}">
           <xsl:element name="TH" use-attribute-sets="left-column">
              <STRONG><xsl:value-of select="$label"/></STRONG>
           </xsl:element>
         </A>
         <td>
           <UL>
             <xsl:for-each select="/project/document[@category = $category]">
                 <LI><A HREF="{@href}"><xsl:apply-templates select="*|text()"/></A></LI>
             </xsl:for-each>
           </UL>
         </td>
       </TR>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>
