<?xml version="1.0" encoding="utf8"?>
<!--
$Id: hints.xsl,v 2.11 2005/01/04 17:18:46 jmates Exp $

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

Generates output suitable for posting onto macosxhints.com.

-->
<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"/>
  <xsl:variable name="default.subdir"/>
  <xsl:output method="html" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:preserve-space elements="info note warn li"/>
<!-- 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">
<!--    <html>
      <head>
        <title>
          <xsl:value-of select="summary/title"/>
        </title>
      </head>
      <body>
        <p>
          <xsl:value-of select="summary/title"/>
        </p>
        <p>These notes are <a href="FIXME">reproduced from the following location</a> for better visibility.  Some formatting has been lost from the original.</p> -->
<!--        <xsl:apply-templates select="section"/> -->
    <xsl:apply-templates/>
<!--      </body>
    </html> -->
  </xsl:template>
  <xsl:template match="title">
    <p>
      <b>
        <em>
          <xsl:apply-templates/>
        </em>
      </b>
    </p>
  </xsl:template>
  <xsl:template match="info[../li]|note[../li]|warn[../li]">
    <xsl:call-template name="genElement">
      <xsl:with-param name="element" select="'p'"/>
    </xsl:call-template>
  </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}">
      <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>
      <xsl:when test="@xlink:href">
        <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[../li]">
    <xsl:call-template name="datablock"/>
  </xsl:template>
  <xsl:template name="datablock">
    <xsl:element name="pre">
<!-- 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'">
            <b>
              <xsl:apply-templates/>
            </b>
          </xsl:when>
          <xsl:when test="name()='old-line'">
            <i>
              <xsl:apply-templates/>
            </i>
          </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">
    <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">
        <br/>
      </xsl:when>
      <xsl:otherwise>
        <br/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="li">
    <xsl:element name="{name()}">
      <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">
    <a href="{@xlink:href}">
      <xsl:apply-templates/>
    </a>
  </xsl:template>
  <xsl:template match="image|image-svg">
    <p>
      <xsl:text>Image skipped: </xsl:text>
      <xsl:value-of select="@xlink:href"/>
    </p>
  </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|input">
    <xsl:call-template name="genLinkElement">
      <xsl:with-param name="element" select="'i'"/>
    </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="'em'"/>
    </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>
      <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">
<!-- 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: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: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://search.cpan.org/perldoc?</xsl:text>
            <xsl:value-of select="normalize-space(text())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:call-template name="genElement">
        <xsl:with-param name="element" select="'tt'"/>
      </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: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:stylesheet>
