<?xml version="1.0"?> 
<!--
  Copyright (c) 2002 Manuel Amago

  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
<xsl:output doctype-public="-//W3C//DTD HTML 3.2 Final//EN"
    method="html" indent="yes" cdata-section-elements="script"/>

<xsl:variable name="site_name">Manuel Amago</xsl:variable>
<xsl:key match="section" name="toc" use="title"/>


<xsl:template match="page">
<HTML><HEAD>
<!-- Title -->
<TITLE><xsl:if test="not(header/title=$site_name)">Manuel Amago: </xsl:if>
<xsl:value-of select="header/title"/></TITLE>
</HEAD><BODY>


<!-- Menu -->
<!-- FIXME: Is there a way to automagically generate this??? -->
<CENTER><A href="index.html">Home</A>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>|
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<A href="ramblings.html">Ramblings</A>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>|
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<A href="code.html">Code Samples</A>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>|
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<A href="books.html">Book Reviews</A>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>|
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<A href="links.html">Links</A>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>|
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<A href="family/">Family</A></CENTER><HR/>

<!-- Header -->
<CENTER><H1><xsl:apply-templates select="header/title"/></H1></CENTER><HR/>


<!-- Contents -->
<xsl:apply-templates select="contents"/>


<!-- Footer -->
<P/><HR/><CENTER>Copyright <xsl:text disable-output-escaping="yes">&amp;copy;</xsl:text> 2002
<A href="mailto:mamago@bigfoot.com">Manuel Amago</A>. All Rights Reserved.<BR/>
<!-- FIXME: should create a method/template for introducing links, in case
  I introduce subfolder levels at some point...  -->
<A href="colophon.html">Colophon</A></CENTER><HR/>
</BODY></HTML>
</xsl:template>


<!-- ====== Templates ====== -->

<!-- ============ Normal ============ -->


<xsl:template match="section">
  <A name="{generate-id()}"/>
  <xsl:variable name="level" select="count(ancestor::section)"/>
  <xsl:choose>
    <xsl:when test='$level=0'>
      <xsl:element name="H2">
      <xsl:attribute name="class">
        <xsl:value-of select="$level"/>
      </xsl:attribute>
      <xsl:apply-templates select="./title"/>
    </xsl:element> 
    </xsl:when>
    <xsl:when test='$level=1'>
      <xsl:element name="H3">
      <xsl:attribute name="class">
        <xsl:value-of select="$level"/>
      </xsl:attribute>
      <xsl:apply-templates select="./title"/>
    </xsl:element> 
    </xsl:when>
    <xsl:otherwise>
      <xsl:element name="H4">
      <xsl:attribute name="class">
        <xsl:value-of select="$level"/>
      </xsl:attribute>
      <xsl:apply-templates select="./title"/>
    </xsl:element>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates select="p|section|links|toc"/>
</xsl:template>


<xsl:template match="links">
  <DL>
    <xsl:for-each select="entry">
      <DT><xsl:apply-templates select="link"/></DT><DD><xsl:apply-templates select="desc"/></DD>
    </xsl:for-each>
  </DL>
</xsl:template>


<xsl:template match="p">
  <P><xsl:apply-templates/></P>
</xsl:template>


<xsl:template match="i">
  <I><xsl:apply-templates/></I>
</xsl:template>


<xsl:template match="b">
  <B><xsl:apply-templates/></B>
</xsl:template>


<xsl:template match="link">
  <A href="{@url}"><xsl:apply-templates/></A>
</xsl:template>


<xsl:template match="script">
<xsl:if test="@code"><xsl:value-of select="." disable-output-escaping="yes"/></xsl:if>
<xsl:if test="not(@code)"><script>
  <xsl:if test="@src"><xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute></xsl:if>
  <xsl:if test="@type"><xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute></xsl:if>
  <xsl:if test="@language"><xsl:attribute name="language"><xsl:value-of select="@language"/></xsl:attribute></xsl:if>
  <xsl:if test="@charset"><xsl:attribute name="charset"><xsl:value-of select="@charset"/></xsl:attribute></xsl:if>
  <xsl:if test="@defer"><xsl:attribute name="defer"><xsl:value-of select="@defer"/></xsl:attribute></xsl:if>
  <xsl:apply-templates/>
  </script>
</xsl:if>
</xsl:template>


<xsl:template match="abstract">
  <xsl:if test="@title"><B><xsl:value-of select="@title"/></B><BR/></xsl:if>
  <xsl:if test="not(@title)"><B>Abstract</B><BR/></xsl:if>
  <blockquote><xsl:apply-templates/></blockquote>
</xsl:template>

<xsl:template match="toc">
  <xsl:if test="@title"><B><xsl:value-of select="@title"/></B><BR/></xsl:if>
  <xsl:if test="not(@title)"><B>Table of Contents</B><BR/></xsl:if>
  <UL><xsl:apply-templates select="../section" mode="toc"/></UL>
  <HR/>
</xsl:template>


<!-- ============ toc: Table of Contents ============ -->


<xsl:template match="section" mode="toc">
  <xsl:apply-templates select="title|section" mode="intoc"/>
</xsl:template>


<xsl:template match="section" mode="intoc">
  <UL><xsl:apply-templates select="title|section" mode="intoc"/></UL>
</xsl:template>


<xsl:template match="title" mode="intoc">
  <LI><A href="#{generate-id(..)}"><xsl:apply-templates/></A>. <xsl:apply-templates select="following-sibling::precis"/></LI>
</xsl:template>

</xsl:stylesheet>
