<?xml version="1.0" encoding="utf8"?>
<!--
$Id: printable.xsl,v 2.11 2005/07/16 18:20:51 jmates Exp $

The author disclaims all copyrights and releases this document into
the public domain.

Stylesheet for printable output.

TODO fully qualify relative URI somehow.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0">
  <xsl:import href="default.xsl"/>
<!-- HTML instead of XHTML as all bots likely do not support XHTML -->
  <xsl:output method="html" indent="no"/>
  <xsl:strip-space elements="*"/>
  <xsl:preserve-space elements="info note warn li"/>
  <xsl:param name="stylesheet.version">
    <xsl:text>$Id: printable.xsl,v 2.11 2005/07/16 18:20:51 jmates Exp $</xsl:text>
  </xsl:param>
<!-- use default stylesheet (CSS) to avoid folks keying in on searchbot term -->
  <xsl:param name="request.preferred_style">
    <xsl:text>printable</xsl:text>
  </xsl:param>
<!-- disable following, bots do not need -->
  <xsl:template name="navlinks"/>
  <xsl:template name="page-header">
    <xsl:apply-templates select="summary/title"/>
    <xsl:if test="string-length($default.uri) &gt; 0">
<!-- KLUGE include sial.org directly, as $default.site uses high port proxy address -->
      <p>Source: <a href="http://sial.org{$default.uri}">http://sial.org<xsl:value-of select="$default.uri"/></a></p>
    </xsl:if>
    <xsl:if test="summary/description">
      <p class="info">
        <xsl:value-of select="summary/description"/>
      </p>
    </xsl:if>
    <xsl:if test="summary/version">
      <p class="version">
        <xsl:value-of select="summary/version"/>
      </p>
    </xsl:if>
    <xsl:if test="summary/abstract">
      <h2>Abstract</h2>
      <p class="info">
        <xsl:value-of select="summary/abstract"/>
      </p>
    </xsl:if>
  </xsl:template>
  <xsl:template name="page-footer">
    <h2>References</h2>
    <xsl:apply-templates select=".//*/@xlink:href" mode="links"/>
  </xsl:template>
  <xsl:template match="image-svg/@xlink:href|image/@xlink:href" mode="links"/>
  <xsl:template match="@xlink:href" mode="links">
    <p class="info">
      <span class="footnote">
        <xsl:number level="any" count="*[@xlink:href[name(..) != 'image' and name(..) != 'image-svg']]" format="1"/>
      </span>
      <xsl:text> </xsl:text>
      <xsl:value-of select="."/>
    </p>
  </xsl:template>
  <xsl:template name="genLinkElement">
    <xsl:param name="element"/>
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="$element"/>
    </xsl:call-template>
    <xsl:if test="@xlink:href">
      <span class="footnote">
        <xsl:number level="any" count="*[@xlink:href[name(..) != 'image' and name(..) != 'image-svg']]" format="1"/>
      </span>
    </xsl:if>
  </xsl:template>
  <xsl:template match="link">
    <xsl:apply-templates/>
    <xsl:if test="@xlink:href">
      <span class="footnote">
        <xsl:number level="any" count="*[@xlink:href]" format="1"/>
      </span>
    </xsl:if>
  </xsl:template>
  <xsl:template match="man">
    <xsl:call-template name="man"/>
  </xsl:template>
  <xsl:template match="perl-module">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'tt'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="perl-pod">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'tt'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="acronym">
    <xsl:variable name="currentAbbr">
      <xsl:value-of select="abbr"/>
    </xsl:variable>
    <xsl:choose>
<!-- funny test is to determine whether this is the first acronym of a particular kind so we can treat it differently -->
      <xsl:when test="generate-id(//acronym[child::abbr=$currentAbbr]) = generate-id()">
        <xsl:value-of select="name"/>
        <xsl:text> (</xsl:text>
        <xsl:value-of select="abbr"/>
        <xsl:text>)</xsl:text>
        <xsl:if test="@xlink:href">
          <span class="footnote">
            <xsl:number level="any" count="*[@xlink:href]" format="1"/>
          </span>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <acronym title="{name}">
          <xsl:value-of select="abbr"/>
        </acronym>
        <xsl:if test="@xlink:href">
          <span class="footnote">
            <xsl:number level="any" count="*[@xlink:href]" format="1"/>
          </span>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="title">
    <xsl:variable name="hlevel">
      <xsl:choose>
        <xsl:when test="count(ancestor-or-self::section)+1 &gt; 6">
          <xsl:text>h6</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>h</xsl:text>
          <xsl:value-of select="count(ancestor-or-self::section)+1"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:element name="{$hlevel}">
      <xsl:element name="a">
        <xsl:attribute name="name">
          <xsl:text>s</xsl:text>
          <xsl:number count="section" level="multiple" format="1.1"/>
        </xsl:attribute>
        <xsl:apply-templates/>
      </xsl:element>
    </xsl:element>
  </xsl:template>
  <xsl:template match="rfc">
    <xsl:text>[RFC </xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>]</xsl:text>
  </xsl:template>
</xsl:stylesheet>
