<?xml version="1.0" encoding="utf8"?>
<!-- <!DOCTYPE xsl:stylesheet SYSTEM "../xslt1.dtd"> -->
<!--
$Id: default.xsl,v 1.123 2007/07/09 01:18:11 jmates Exp $

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

Shared common templates for conversion of XML documents written with
the eolas DTD into XHTML.  Use something like

<xsl:import href="default.xsl"/>

at the top of the stylesheet to pull in the templates below.

This stylesheet was created using Mozilla (1.1 on Mac OS X) as the
reference for display.
-->
<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="../shared.xsl"/>
  <xsl:output method="xml" media-type="text/html" indent="no"/>
  <xsl:strip-space elements="*"/>
  <xsl:preserve-space elements="info note warn li"/>
  <xsl:param name="default.uri"/>
  <xsl:param name="request.preferred_style"/>
  <xsl:param name="stylesheet.version">
    <xsl:text>$Id: default.xsl,v 1.123 2007/07/09 01:18:11 jmates Exp $</xsl:text>
  </xsl:param>
<!-- basic root element and section handling. -->
<!-- these will the templates most often overridden -->
<!-- you may also want to handle the summary element -->
  <xsl:template match="eolas">
    <xsl:element name="html">
      <xsl:choose>
        <xsl:when test="@xml:lang">
          <xsl:attribute name="lang">
            <xsl:value-of select="@xml:lang"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="lang">
            <xsl:text>en-US</xsl:text>
          </xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
      <head>
        <title>
          <xsl:value-of select="summary/title"/>
        </title>
<!-- figure out CSS stylesheet to use by param name passed in -->
        <xsl:element name="link">
          <xsl:attribute name="rel">stylesheet</xsl:attribute>
          <xsl:attribute name="type">text/css</xsl:attribute>
          <xsl:attribute name="href">
            <xsl:text>/_xs/eolas/</xsl:text>
            <xsl:choose>
              <xsl:when test="string-length($request.preferred_style) &gt; 0">
                <xsl:value-of select="$request.preferred_style"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>default</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:text>.css</xsl:text>
          </xsl:attribute>
        </xsl:element>
<!--        <link rel="P3Pv1" href="/w3c/p3p.xml"/> -->
        <meta name="MSSmartTagsPreventParsing" content="TRUE"/>
      </head>
      <body>
        <div class="header">
          <xsl:call-template name="navlinks"/>
          <xsl:apply-templates select="summary/title"/>
        </div>
        <xsl:call-template name="page-header"/>
        <div class="bodymain">
          <xsl:apply-templates select="section"/>
          <xsl:call-template name="page-footer"/>
        </div>
      </body>
    </xsl:element>
  </xsl:template>
<!-- stuff after <body> but before main content sections -->
  <xsl:template name="page-header">
<!-- quick sub-section links -->
    <xsl:if test="count(section) &gt; 1">
      <div class="subsection">
        <xsl:for-each select="section">
          <xsl:if test="string-length(title) &gt; 0">
            <xsl:element name="a">
              <xsl:attribute name="href">
                <xsl:text>#s</xsl:text>
                <xsl:number count="section" level="multiple" format="1.1"/>
              </xsl:attribute>
              <xsl:apply-templates select="title" mode="nosub"/>
            </xsl:element>
            <xsl:if test="not(position()=last())">
              <xsl:text> | </xsl:text>
            </xsl:if>
          </xsl:if>
        </xsl:for-each>
      </div>
    </xsl:if>
  </xsl:template>
<!-- page closing remarks -->
  <xsl:template name="page-footer">
    <div class="footer">
      <a href="/">
        <img style="float: right; margin-top: 1em; margin-right: 1em; margin-bottom: 5em" src="/sial.icon2.gif" width="64" height="64"/>
      </a>
      <xsl:if test="string-length(summary/rights) &gt; 0">
        <p>
          <xsl:value-of select="summary/rights"/>
        </p>
      </xsl:if>
<!-- TODO style view not working, fix, then re-enable -->
<!--      <xsl:text>Format: </xsl:text> -->
<!-- KLUGE search bots pick up on XML, show it rather than primary page.
Stupid, stupid google bot! Also like to show data/shell blocks instead, no
idea what to do there, given google's mandate to "do not change content" when
their flawed bot stumbles through... :( -->
<!--      <xsl:text>Original XML</xsl:text> -->
<!--      <xsl:call-template name="style-choice">
        <xsl:with-param name="style-file">xml</xsl:with-param>
        <xsl:with-param name="style-title">Original XML</xsl:with-param>
      </xsl:call-template> -->
<!--      <xsl:if test="descendant::book">
        <xsl:text> | </xsl:text>
        <xsl:call-template name="style-choice">
          <xsl:with-param name="style-file">book-info</xsl:with-param>
          <xsl:with-param name="style-title">Book Details</xsl:with-param>
        </xsl:call-template>
      </xsl:if>
      <xsl:if test="descendant::data">
        <xsl:text> | </xsl:text>
        <xsl:call-template name="style-choice">
          <xsl:with-param name="style-file">data-blocks</xsl:with-param>
          <xsl:with-param name="style-title">Data Blocks</xsl:with-param>
        </xsl:call-template>
      </xsl:if> -->
<!-- since we're at the root node, should be able to walk down and look for any shell elements -->
<!--      <xsl:if test="descendant::shell">
        <xsl:text> | </xsl:text>
        <xsl:call-template name="style-choice">
          <xsl:with-param name="style-file">shell-code</xsl:with-param>
          <xsl:with-param name="style-title">Shell Code</xsl:with-param>
        </xsl:call-template>
      </xsl:if> -->
      <p><a href="/contact/">Questions or comments about this page?</a> Current ruminations available on <a href="/blog/">my blog</a>.
      </p>
      <p>
        <tt>
          <xsl:if test="summary/version">
            <xsl:value-of select="summary/version"/>
          </xsl:if>
        </tt>
      </p>
    </div>
  </xsl:template>
  <xsl:template name="style-choice">
    <xsl:param name="style-file"/>
    <xsl:param name="style-title"/>
    <xsl:element name="a">
      <xsl:attribute name="href">
<!--        <xsl:value-of select="$default.uri"/> -->
        <xsl:text>?style=</xsl:text>
        <xsl:value-of select="$style-file"/>
      </xsl:attribute>
      <xsl:value-of select="$style-title"/>
    </xsl:element>
  </xsl:template>
  <xsl:template match="section">
    <xsl:apply-templates/>
  </xsl:template>
<!-- sub-section elements follow; these generally will not need -->
<!-- to be overridden -->
  <xsl:template match="title" mode="nosub">
    <xsl:apply-templates/>
  </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>
<!-- quick sub-section links -->
    <xsl:if test="count(../section) &gt; 1">
      <div class="subsection">
        <xsl:for-each select="../section">
          <xsl:if test="string-length(title) &gt; 0">
            <xsl:element name="a">
              <xsl:attribute name="href">
                <xsl:text>#s</xsl:text>
                <xsl:number count="section" level="multiple" format="1.1"/>
              </xsl:attribute>
              <xsl:apply-templates select="title" mode="nosub"/>
            </xsl:element>
            <xsl:if test="not(position()=last())">
              <xsl:text> | </xsl:text>
            </xsl:if>
          </xsl:if>
        </xsl:for-each>
      </div>
    </xsl:if>
  </xsl:template>
  <xsl:template match="info|note|warn">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'p'"/>
    </xsl:call-template>
  </xsl:template>
<!-- abstract generation of elements <p>, <div>, and similar;
generally stuff that cannot have links... -->
  <xsl:template name="genElement">
    <xsl:param name="element"/>
    <xsl:element name="{$element}">
<!-- figure out CSS passthrough -->
      <xsl:choose>
        <xsl:when test="@style">
          <xsl:attribute name="style">
            <xsl:value-of select="@style"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@class">
          <xsl:attribute name="class">
            <xsl:value-of select="@class"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@xml:lang">
          <xsl:attribute name="class">
            <xsl:text>lang-</xsl:text>
            <xsl:value-of select="@xml:lang"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="class">
            <xsl:value-of select="name()"/>
          </xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>
<!-- as genElement, but with href wrapper, if required -->
  <xsl:template name="genLinkElement">
    <xsl:param name="element"/>
    <xsl:choose>
<!-- need ancestor::title check to disable links when dealing with title children -->
      <xsl:when test="@xlink:href and not(ancestor::title)">
        <a href="{@xlink:href}">
          <xsl:call-template name="genElement">
            <xsl:with-param name="element" select="$element"/>
          </xsl:call-template>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="genElement">
          <xsl:with-param name="element" select="$element"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="data">
    <xsl:call-template name="datablock"/>
  </xsl:template>
  <xsl:template name="datablock">
    <xsl:element name="p">
<!-- figure out CSS passthrough -->
      <xsl:choose>
        <xsl:when test="@style">
          <xsl:attribute name="style">
            <xsl:value-of select="@style"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@class">
          <xsl:attribute name="class">
            <xsl:value-of select="@class"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@xml:lang">
          <xsl:attribute name="class">
            <xsl:text>lang-</xsl:text>
            <xsl:value-of select="@xml:lang"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="descendant::shell">
              <xsl:attribute name="class">
                <xsl:value-of select="name()"/>
                <xsl:text>-shell</xsl:text>
              </xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="class">
                <xsl:value-of select="name()"/>
              </xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
<!-- grr, whitespace goes funny if use template for these... -->
      <xsl:for-each select="line|old-line|shell">
        <xsl:if test="@prefix">
          <xsl:value-of select="@prefix"/>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="name()='shell' and string-length(.) = 0">
            <kbd> </kbd>
          </xsl:when>
          <xsl:when test="name()='shell'">
            <kbd>
              <xsl:apply-templates/>
            </kbd>
          </xsl:when>
          <xsl:when test="name()='old-line'">
            <span class="old-line">
              <xsl:apply-templates/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
<!-- some browsers may need trailing breaks, handle with CSS if possible -->
        <xsl:if test="not(position()=last())">
          <br/>
        </xsl:if>
      </xsl:for-each>
    </xsl:element>
  </xsl:template>
<!-- "recommended br" to force linebreaks in <line> and <shell> elements
to avoid the run-off-right-edge-of-screen problem in certain browsers. -->
  <xsl:template match="rbr">
<!-- ahhh, but what kind of br... -->
    <xsl:choose>
      <xsl:when test="ancestor::shell">
        <xsl:text>\</xsl:text>
        <br/>
        <xsl:choose>
          <xsl:when test="string-length(ancestor::shell/@prefix) &lt;= 2">
            <xsl:call-template name="space-pad">
              <xsl:with-param name="padLength" select="string-length(ancestor::shell/@prefix)"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="space-pad">
              <xsl:with-param name="padLength" select="2"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:when test="ancestor::line">
        <span class="rbr">
          <xsl:text>↵</xsl:text>
        </span>
        <br/>
      </xsl:when>
      <xsl:otherwise>
        <br/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="space-pad">
    <xsl:param name="i" select="1"/>
    <xsl:param name="padLength" select="1"/>
    <xsl:variable name="testPassed">
      <xsl:if test="$i &lt;= $padLength">
        <xsl:text>true</xsl:text>
      </xsl:if>
    </xsl:variable>
    <xsl:if test="$testPassed='true'">
      <xsl:text> </xsl:text>
      <xsl:call-template name="space-pad">
        <xsl:with-param name="i" select="$i + 1"/>
        <xsl:with-param name="padLength" select="$padLength"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
<!-- list related stuff -->
  <xsl:template match="list">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'ul'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="enum">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'ol'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="li">
    <xsl:element name="{name()}">
      <xsl:choose>
        <xsl:when test="@style">
          <xsl:attribute name="style">
            <xsl:value-of select="@style"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@class">
          <xsl:attribute name="class">
            <xsl:value-of select="@class"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@xml:lang">
          <xsl:attribute name="class">
            <xsl:text>lang-</xsl:text>
            <xsl:value-of select="@xml:lang"/>
          </xsl:attribute>
        </xsl:when>
      </xsl:choose>
      <xsl:apply-templates/>
<!-- kluge spacing between adjacent li; only other way appears to be with CSS2 (I forget how :)  this is due to my dislike of browsers bunching list elements all together by default -->
<!--     <xsl:if test="name((following-sibling::*)[1])='li'"> -->
      <xsl:choose>
        <xsl:when test="name((following::*)[1])='li'">
          <br/>
          <xsl:text> </xsl:text>
        </xsl:when>
        <xsl:when test="name((following-sibling::*)[1])='list'">
          <br/>
          <xsl:text> </xsl:text>
        </xsl:when>
        <xsl:when test="name((following-sibling::*)[1])='enum'">
          <br/>
          <xsl:text> </xsl:text>
        </xsl:when>
      </xsl:choose>
    </xsl:element>
  </xsl:template>
  <xsl:template match="link">
    <xsl:choose>
      <xsl:when test="ancestor::title">
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:otherwise>
        <a href="{@xlink:href}">
          <xsl:apply-templates/>
        </a>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="image">
    <xsl:element name="img">
      <xsl:attribute name="src">
        <xsl:value-of select="@xlink:href"/>
      </xsl:attribute>
      <xsl:if test="@width">
        <xsl:attribute name="width">
          <xsl:value-of select="@width"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height">
        <xsl:attribute name="height">
          <xsl:value-of select="@height"/>
        </xsl:attribute>
      </xsl:if>
<!-- figure out CSS passthrough -->
      <xsl:choose>
        <xsl:when test="@style">
          <xsl:attribute name="style">
            <xsl:value-of select="@style"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@class">
          <xsl:attribute name="class">
            <xsl:value-of select="@class"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="@xml:lang">
          <xsl:attribute name="class">
            <xsl:text>lang-</xsl:text>
            <xsl:value-of select="@xml:lang"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="class">
            <xsl:value-of select="name()"/>
          </xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
  </xsl:template>
<!-- SVG need special handling, as they are XML and width/height can be queried on the fly. -->
  <xsl:template match="image-svg">
<!-- we need the funny /*/ selection of <svg> root element to avoid having to name and use the SVG namespace in this stylesheet; /svg:svg/ if xmlns:svg is setup. -->
    <embed src="{@xlink:href}" style="width: {document(@xlink:href)/*/@width}; height: {document(@xlink:href)/*/@height};"/>
  </xsl:template>
<!-- these are for custom markup of data stuff -->
<!-- input is stuff people presumably type in, comment is to demark -->
<!-- comments in code differently for easier reading -->
  <xsl:template match="comment">
    <xsl:call-template name="genLinkElement">
      <xsl:with-param name="element" select="'span'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="input">
    <xsl:call-template name="genLinkElement">
      <xsl:with-param name="element" select="'kbd'"/>
    </xsl:call-template>
  </xsl:template>
<!-- "computer-related" markup stuff; let CSS handle how these look -->
  <xsl:template match="cmd|cmd-arg|code|file|file-glob|gui|host">
    <xsl:call-template name="genLinkElement">
      <xsl:with-param name="element" select="'tt'"/>
    </xsl:call-template>
  </xsl:template>
<!-- stuff translated directly into HTML -->
  <xsl:template match="em|span">
    <xsl:call-template name="genLinkElement">
      <xsl:with-param name="element" select="name()"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="applekb">
    <xsl:choose>
      <xsl:when test="string-length(name)">
        <xsl:text>Apple KB </xsl:text>
        <xsl:value-of select="kbid"/>
        <xsl:text>: “</xsl:text>
        <xsl:value-of select="name"/>
        <xsl:text>”</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>Apple KB </xsl:text>
        <xsl:value-of select="kbid"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="applekb[ancestor::title]">
    <xsl:call-template name="applekb"/>
  </xsl:template>
  <xsl:template match="applekb">
    <a href="http://www.info.apple.com/kbnum/n{kbid}">
      <xsl:call-template name="applekb"/>
    </a>
  </xsl:template>
<!-- man pages -->
  <xsl:template name="man">
    <tt class="{name()}">
      <xsl:value-of select="normalize-space(text())"/>
      <xsl:text>(</xsl:text>
      <xsl:value-of select="@section"/>
      <xsl:text>)</xsl:text>
    </tt>
  </xsl:template>
  <xsl:template match="man[ancestor::title]">
    <xsl:call-template name="man"/>
  </xsl:template>
  <xsl:template match="man[ancestor::link]">
    <xsl:call-template name="man"/>
  </xsl:template>
  <xsl:template match="man">
<!-- default link into FreeBSD man CGI for time being -->
    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@xlink:href">
            <xsl:value-of select="@xlink:href"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>http://www.FreeBSD.org/cgi/man.cgi?query=</xsl:text>
            <xsl:value-of select="."/>
            <xsl:if test="@section">
              <xsl:text>&amp;sektion=</xsl:text>
              <xsl:value-of select="@section"/>
            </xsl:if>
            <xsl:if test="@system">
              <xsl:text>&amp;manpath=</xsl:text>
              <xsl:value-of select="@system"/>
            </xsl:if>
<!-- not supporting arch/revision tags, as no
            consistent means of hooking them up with
            the FreeBSD man.cgi query; will need to
            setup a localized man.cgi that can search
            for things across archs better... sigh -->
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:text>FreeBSD man page search for </xsl:text>
        <xsl:value-of select="normalize-space(text())"/>
        <xsl:if test="@section">
          <xsl:text>, section </xsl:text>
          <xsl:value-of select="@section"/>
        </xsl:if>
        <xsl:if test="@system">
          <xsl:text> on </xsl:text>
          <xsl:value-of select="@system"/>
        </xsl:if>
        <xsl:if test="@revision">
          <xsl:text> version </xsl:text>
          <xsl:value-of select="@revision"/>
        </xsl:if>
        <xsl:if test="@arch">
          <xsl:text>, </xsl:text>
          <xsl:value-of select="@arch"/>
          <xsl:text> platform</xsl:text>
        </xsl:if>
      </xsl:attribute>
      <xsl:call-template name="man"/>
    </xsl:element>
  </xsl:template>
  <xsl:template match="perl-module[ancestor::title]">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'tt'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="perl-module">
    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@xlink:href">
            <xsl:value-of select="@xlink:href"/>
          </xsl:when>
          <xsl:otherwise>
<!--            <xsl:text>http://www.perldoc.com/cpan/</xsl:text> -->
<!-- folds ::'s into / -->
<!--            <xsl:value-of select="translate(normalize-space(translate(text(), ':', ' ')), ' ', '/')"/>
            <xsl:text>.html</xsl:text> -->
            <xsl:text>http://search.cpan.org/perldoc/</xsl:text>
            <xsl:value-of select="text()"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:text>Documentation on the </xsl:text>
        <xsl:value-of select="normalize-space(text())"/>
        <xsl:text> Perl module</xsl:text>
      </xsl:attribute>
      <xsl:call-template name="genElement">
        <xsl:with-param name="element" select="'tt'"/>
      </xsl:call-template>
    </xsl:element>
  </xsl:template>
  <xsl:template match="perl-pod[ancestor::title]">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'tt'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="perl-pod">
    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@xlink:href">
            <xsl:value-of select="@xlink:href"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>http://perldoc.perl.org/</xsl:text>
            <xsl:value-of select="normalize-space(text())"/>
            <xsl:text>.html</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:text>Perl programmers reference for </xsl:text>
        <xsl:value-of select="normalize-space(text())"/>
      </xsl:attribute>
      <xsl:call-template name="genElement">
        <xsl:with-param name="element" select="'tt'"/>
      </xsl:call-template>
    </xsl:element>
  </xsl:template>
  <xsl:template match="perl-func">
    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@xlink:href">
            <xsl:value-of select="@xlink:href"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>http://perldoc.perl.org/functions/</xsl:text>
            <xsl:value-of select="normalize-space(text())"/>
            <xsl:text>.html</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:text>Documentation on the Perl </xsl:text>
        <xsl:value-of select="normalize-space(text())"/>
        <xsl:text> function</xsl:text>
      </xsl:attribute>
      <xsl:call-template name="genElement">
        <xsl:with-param name="element" select="'code'"/>
      </xsl:call-template>
    </xsl:element>
  </xsl:template>
  <xsl:template match="rfc[ancestor::title]">
    <xsl:text>[RFC </xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>]</xsl:text>
  </xsl:template>
  <xsl:template match="rfc">
    <xsl:text>[</xsl:text>
    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@xlink:href">
            <xsl:value-of select="@xlink:href"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>http://www.rfc-editor.org/rfc/rfc</xsl:text>
            <xsl:value-of select="normalize-space(text())"/>
            <xsl:text>.txt</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:text>Requests for Comments (RFC) number </xsl:text>
        <xsl:value-of select="normalize-space(text())"/>
      </xsl:attribute>
      <xsl:text>RFC </xsl:text>
      <xsl:value-of select="."/>
    </xsl:element>
    <xsl:text>]</xsl:text>
  </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()">
<!-- linked or not? -->
        <xsl:choose>
          <xsl:when test="@xlink:href and not(ancestor::title)">
            <a href="{@xlink:href}">
              <xsl:value-of select="name"/>
              <xsl:text> (</xsl:text>
              <xsl:value-of select="abbr"/>
              <xsl:text>)</xsl:text>
            </a>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="name"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="abbr"/>
            <xsl:text>)</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
<!-- linked or not? -->
        <xsl:choose>
          <xsl:when test="@xlink:href and not(ancestor::title)">
            <a href="{@xlink:href}">
              <acronym title="{name}">
                <xsl:value-of select="abbr"/>
              </acronym>
            </a>
          </xsl:when>
          <xsl:otherwise>
            <acronym title="{name}">
              <xsl:value-of select="abbr"/>
            </acronym>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="book[ancestor::title]">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'span'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="book">
    <xsl:choose>
      <xsl:when test="@xlink:href or @isbn">
        <xsl:element name="a">
          <xsl:attribute name="href">
            <xsl:choose>
              <xsl:when test="@isbn">
                <xsl:text>http://www.amazon.com/o/ASIN/</xsl:text>
                <xsl:value-of select="normalize-space(@isbn)"/>
                <xsl:text>/sialorg-20/ref=nosim</xsl:text>
              </xsl:when>
              <xsl:when test="@xlink:href">
                <xsl:value-of select="@xlink:href"/>
              </xsl:when>
            </xsl:choose>
          </xsl:attribute>
          <xsl:if test="@isbn">
            <xsl:attribute name="title">
              <xsl:text>ISBN: </xsl:text>
              <xsl:value-of select="normalize-space(@isbn)"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:call-template name="genElement">
            <xsl:with-param name="element" select="'span'"/>
          </xsl:call-template>
        </xsl:element>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="genElement">
          <xsl:with-param name="element" select="'span'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
