<?xml version="1.0" encoding="UTF-8" ?>
<!--
    Document   : page.xsl
    Created on : 29 July 2004, 23:01
    Author     : owen
    Description:
        Generate my website from XML data.
        This is the dumbed down version that works directly in some browsers.
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" encoding="iso-8859-1"
    doctype-system="http://www.w3.org/TR/html4/strict.dtd"
    doctype-public="-//W3C//DTD HTML 4.01//EN"/>
  <xsl:param name="referer" select="document('referer.shtml')"/>
  <xsl:param name="linksuffix">.xml</xsl:param>
  <xsl:variable name="style" select="substring-after($referer,'?style=')"/>
  <xsl:variable name="linkqs">
    <xsl:choose>
      <xsl:when test="$style">?style=<xsl:value-of select="$style"/></xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:variable>
  <xsl:strip-space elements="*"/>
  <xsl:preserve-space elements="title link script"/>
  <xsl:variable name="root" select="/"/>
  <xsl:variable name="pagename" select="/page/@name"/>

  <xsl:template match="/page">
    <html lang="en">
      <head>
        <xsl:comment>
          <xsl:value-of select="$style"/>
        </xsl:comment>
        <title>
          <xsl:value-of select="title"/>
        </title>
        <link href="normal.css" rel="stylesheet" type="text/css"/>
        <style type="text/css" media="all">
          <xsl:choose>
            <xsl:when test="$style = 'hmenu'">@import url(hmenu.css);</xsl:when>
            <xsl:otherwise>@import url(menu.css);</xsl:otherwise>
          </xsl:choose>
          <xsl:for-each select="style"> @import url(<xsl:value-of select="."/>); </xsl:for-each>
          <xsl:if test="rightcol"> div#content { padding-right: <xsl:value-of
              select="rightcol/@width"/>; z-index: 50; } div#rightcol { position: absolute; top:
            0em; right: 0em; width: <xsl:value-of select="rightcol/@width"/>; padding: 1em; }
            div#rightcol div { margin-right: 1em; border: #40c0c0 2px solid; padding: 2em; color:
            black; background: white; font: .8em arial, sans-serif; } </xsl:if>
        </style>
      </head>
      <body>
        <xsl:apply-templates select="rightcol" mode="position"/>
        <xsl:choose>
          <xsl:when test="$style = 'hmenu'">
            <xsl:call-template name="links"/>
            <xsl:call-template name="content"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="content"/>
            <xsl:call-template name="links"/>
          </xsl:otherwise>
        </xsl:choose>
      </body>
    </html>
  </xsl:template>
  <xsl:template name="content">
    <div id="content">
      <div>
        <xsl:apply-templates/>
        <hr style="clear: both"/>
        <p>
          <img src="address.gif" alt="My e-mail address as a graphic"/>
        </p>
      </div>
    </div>
  </xsl:template>
  <xsl:template name="links">
    <div id="links">
      <div>
        <xsl:apply-templates select="document('menu.xml')/menu" mode="menu"/>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="style"/>
  <xsl:template match="rightcol"/>
  <xsl:template match="rightcol" mode="position">
    <div id="rightcol">
      <div>
        <xsl:apply-templates/>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="title">
    <h1 class="c1">
      <xsl:apply-templates/>
    </h1>
  </xsl:template>
  <xsl:template match="img">
    <xsl:choose>
      <xsl:when test="@full">
        <a href="{@full}">
          <xsl:copy>
            <xsl:apply-templates select="@*" mode="notfull"/>
          </xsl:copy>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="a[@xref]">
    <a href="{@xref}{$linksuffix}{$linkqs}">
      <xsl:apply-templates select="@*" mode="notxref"/>
      <xsl:apply-templates/>
    </a>
  </xsl:template>

  <xsl:template match="news">
    <li>
      <xsl:if test="@post">
        <xsl:attribute name="class">highlight</xsl:attribute>
      </xsl:if>
      <a href="news:{text()}">
        <xsl:value-of select="."/>
      </a>
    </li>
  </xsl:template>

  <xsl:template match="item" mode="menu">
    <xsl:choose>
      <xsl:when test="@file = $pagename">
        <span class="here">
          <xsl:apply-templates/>
        </span>
      </xsl:when>
      <xsl:otherwise>
        <a href="{@file}{$linksuffix}{$linkqs}">
          <xsl:apply-templates/>
        </a>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="referer">
    <!--<xsl:value-of select="$referer"/>-->
  </xsl:template>

  <!-- some templates to do a except b -->
  <xsl:template match="@full" mode="notfull"/>
  <xsl:template match="@*" mode="notfull">
    <xsl:copy/>
  </xsl:template>
  <xsl:template match="@xref" mode="notxref"/>
  <xsl:template match="@*" mode="notxref">
    <xsl:copy/>
  </xsl:template>

  <!-- By default, copy everything recursively -->
  <xsl:template match="*" priority="-1">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|text()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="text()|@*">
    <xsl:copy-of select="."/>
  </xsl:template>
</xsl:stylesheet>
