<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
                xmlns="http://www.w3.org/TR/xhtml1/transitional"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- Defined shared resources for all Project pages, mainly
     things which get customized in the Appearance elemtn:

   1. Variables
      boxcolor - color spec for box background on left column of table.
      logo - markup to generate the logo at the top of the page.

   2. attribute sets:
      body-attrs - all attributes for HTML body elemnt.
      left-column - all attrs for left-side column in main table.

   3. Templates
       new default templates to pass through all the embedded HTML elements.

-->

  <xsl:variable name="boxcolor">
      <xsl:choose>
        <xsl:when test="/project/appearance/@boxcolor"><xsl:value-of select="/project/appearance/@boxcolor"/></xsl:when>
        <xsl:otherwise>#99CCCC</xsl:otherwise>
      </xsl:choose>
  </xsl:variable>

  <!-- have to put this in a template since variables can't hold just markup -->
  <xsl:template name="logo">
    <xsl:choose>
      <xsl:when test="/project/appearance/@logo">
        <xsl:choose>
          <xsl:when test="/project/appearance/@logo-href">
            <A href="{/project/appearance/@logo-href}">
              <IMG ALT="[Project logo]" BORDER="0" ALIGN="bottom" SRC="{/project/appearance/@logo}"/>
            </A>
          </xsl:when>
          <xsl:otherwise>
            <IMG ALT="[Project logo]" BORDER="0" ALIGN="bottom" SRC="{/project/appearance/@logo}"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <A HREF="http://web.mit.edu/is/"><IMG SRC="http://web.mit.edu/is/graphics/is-logo.gif" ALT="MIT Information Systems" WIDTH="150" HEIGHT="51" BORDER="0" ALIGN="bottom"/></A>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- have to put this in a template since variables can't hold just markup -->
  <xsl:template name="small-logo">
    <xsl:choose>
      <xsl:when test="/project/appearance/@small-logo">
        <xsl:choose>
          <xsl:when test="/project/appearance/@logo-href">
            <A href="{/project/appearance/@logo-href}">
              <IMG ALT="[Project logo]" hspace="4" BORDER="0" ALIGN="bottom" SRC="{/project/appearance/@small-logo}"/>
            </A>
          </xsl:when>
          <xsl:otherwise>
            <IMG ALT="[Project logo]" hspace="4" BORDER="0" ALIGN="bottom" SRC="{/project/appearance/@small-logo}"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <A HREF="http://web.mit.edu/is/"><IMG SRC="http://web.mit.edu/is/graphics/is-logo-small.gif" ALT="MIT Information Systems" HSPACE="4" WIDTH="13" HEIGHT="25" BORDER="0" ALIGN="bottom"/></A>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- attributes for left column of main table: -->
  <xsl:attribute-set name="left-column">
    <xsl:attribute name="VALIGN">center</xsl:attribute>
    <xsl:attribute name="ALIGN">center</xsl:attribute>
    <xsl:attribute name="WIDTH">141</xsl:attribute>
    <xsl:attribute name="BGCOLOR"><xsl:value-of select="$boxcolor"/></xsl:attribute>
  </xsl:attribute-set>
   
  <!-- attributes to apply to HTML BODY, derived from Appearance element. -->
  <xsl:attribute-set name="body-attrs">
    <xsl:attribute name="BGCOLOR">
      <xsl:choose>
        <xsl:when test="/project/appearance/@bgcolor">
            <xsl:value-of select="/project/appearance/@bgcolor"/>
        </xsl:when>
        <xsl:otherwise>#FFFFF7</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>

    <xsl:attribute name="LINK">
      <xsl:choose>
        <xsl:when test="/project/appearance/@link">
            <xsl:value-of select="/project/appearance/@link"/>
        </xsl:when>
        <xsl:otherwise>#008080</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>

    <xsl:attribute name="ALINK">
      <xsl:choose>
        <xsl:when test="/project/appearance/@alink">
            <xsl:value-of select="/project/appearance/@alink"/>
        </xsl:when>
        <xsl:otherwise>#FF0099</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>

    <xsl:attribute name="VLINK">
      <xsl:choose>
        <xsl:when test="/project/appearance/@vlink">
            <xsl:value-of select="/project/appearance/@vlink"/>
        </xsl:when>
        <xsl:otherwise>#004040</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
  </xsl:attribute-set>

<!-- Replace the "default" templates with ones that will copy HTML/XHTML
     tags and text faithfully:
-->
<xsl:template match="text()" priority="-1">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="*" priority="-1">
  <xsl:element name="{name()}">
    <xsl:for-each select="attribute::*">
        <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates select="*|text()"/>
  </xsl:element>
</xsl:template>

<!-- Generate the HEAD element of the HTML; it's in a subtemplate so
     we can change it in one place for every page.
 -->
<xsl:template name="head-element">
    <xsl:param name="title"><xsl:value-of select="/project/@name"/></xsl:param>
    <HEAD>
       <TITLE><xsl:value-of select="$title"/></TITLE>
       <!-- add BASE element? LINKs? -->
    <xsl:comment>Copyright (c) 1999 Massachusetts Institute of Technology</xsl:comment>
    </HEAD>
</xsl:template>

<!-- Generate top-of-page title block with logo, ending in hr -->
<xsl:template name="title-block">
    <xsl:param name="title"><xsl:value-of select="/project/@name"/></xsl:param>
    <xsl:param name="subtitle"/>
    <TABLE BORDER="0" CELLSPACING="0">
       <TR>
          <TD VALIGN="top" WIDTH="164">
          <xsl:call-template name="logo"/>
          </TD>
          <TD VALIGN="bottom">
             <H1><xsl:value-of select="$title"/></H1>
             <xsl:if test="$subtitle">
                <H2><xsl:value-of select="$subtitle"/></H2>
             </xsl:if>
          </TD>
       </TR>
    </TABLE>
    <HR></HR>
</xsl:template>

<!-- Render the "title row" in the main table with project title, contact etc.
     It should be the first real row below the "On this page:" TOC.
  -->
<xsl:template name="title-row">
       <TR>
         <xsl:element name="TH" use-attribute-sets="left-column">
         <STRONG><xsl:value-of select="/project/@name"/></STRONG>
         </xsl:element>
         <TD>
           Email:
           <A><xsl:attribute name="HREF">mailto:<xsl:value-of select="/project/contact/text()"/></xsl:attribute>
           <STRONG>
           <xsl:value-of select="/project/contact/text()"/>
           </STRONG></A><BR/>
           Return to <A href="notebook.html">Project Notebook</A>.<BR/>
         </TD>
       </TR>
</xsl:template>

<!-- Generate trailer block with logo, including hr -->
<xsl:template name="trailer-block">
    <!-- indicate what page is being output; notebook or a subpage. -->
    <xsl:param name="output">subpage</xsl:param>
    <HR/>
    <TABLE BORDER="0" CELLSPACING="0">
       <TR>
          <TD ALIGN="center">
          <P><xsl:call-template name="small-logo"/></P>
          </TD>
          <TD>
             <SMALL>
             <xsl:if test="starts-with($output,'subpage')">
               Return to <A href="notebook.html">Project Notebook</A>.<BR/>
             </xsl:if>
             <A>
             <xsl:attribute name="HREF">mailto:<xsl:value-of select="/project/contact/text()"/></xsl:attribute>
             Comments about these pages</A><BR/>
                  Last modified: <xsl:value-of select="/project/@date"/></SMALL>
          </TD>
       </TR>
    </TABLE>
</xsl:template>


</xsl:stylesheet>
