<?xml version="1.0" encoding="utf8"?>
<!--

$Id: fo-shared.xsl,v 2.9 2004/10/13 23:00:14 jmates Exp $

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

Shared XSLT templates and definitions for conversion of eolas format
into XSL-FO.

http://www.w3.org/TR/xsl/slice6.html#fo-section

This stylesheet is built for Fop 0.20.4, though I build a .fo file
using libxml2's xsltproc for Fop to deal with, as the XSLT engine in
Fop keels over and dies on things like Unicode byte order marks with
obscure errors:

xsltproc fo-slides.xsl foo.xml > temp.fo
java org.apache.fop.apps.Fop temp.fo out.pdf

TODO: investigate keep-together attributes to prevent orphan
lines/entities on spillover pages?

-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fox="http://xml.apache.org/fop/extensions" version="1.0">
  <xsl:attribute-set name="general">
    <xsl:attribute name="font-family">serif</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="summary">
    <xsl:attribute name="text-align">center</xsl:attribute>
  </xsl:attribute-set>
<!-- TODO certain Java XSLT engines get weepy about xsl:use-attribute-sets being an attribute to xsl:attribute-set, so probably need to re-write these for them. -->
  <xsl:attribute-set name="title" xsl:use-attribute-sets="general">
    <xsl:attribute name="font-size">18pt</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="info" xsl:use-attribute-sets="general">
    <xsl:attribute name="space-after.optimum">4pt</xsl:attribute>
    <xsl:attribute name="space-before.optimum">4pt</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="note" xsl:use-attribute-sets="info">
    <xsl:attribute name="border-left-color">#FFCC33</xsl:attribute>
    <xsl:attribute name="border-left-style">solid</xsl:attribute>
    <xsl:attribute name="padding-left">2mm</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="warn" xsl:use-attribute-sets="info">
    <xsl:attribute name="border-left-color">#FF0000</xsl:attribute>
    <xsl:attribute name="border-left-style">solid</xsl:attribute>
    <xsl:attribute name="padding-left">2mm</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="computer">
    <xsl:attribute name="font-family">monospace</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="data" xsl:use-attribute-sets="computer">
    <xsl:attribute name="font-size">7pt</xsl:attribute>
    <xsl:attribute name="space-after">4pt</xsl:attribute>
    <xsl:attribute name="space-before">4pt</xsl:attribute>
    <xsl:attribute name="padding-left">2mm</xsl:attribute>
    <xsl:attribute name="padding-right">2mm</xsl:attribute>
    <xsl:attribute name="padding-top">2mm</xsl:attribute>
    <xsl:attribute name="padding-bottom">2mm</xsl:attribute>
    <xsl:attribute name="border">0.25px solid #000000</xsl:attribute>
    <xsl:attribute name="background-color">#CCFFCC</xsl:attribute>
<!-- force data blocks to left for maximum display space -->
    <xsl:attribute name="start-indent">0mm</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="data-shell" xsl:use-attribute-sets="computer">
    <xsl:attribute name="font-size">7pt</xsl:attribute>
    <xsl:attribute name="padding-left">2mm</xsl:attribute>
    <xsl:attribute name="padding-right">2mm</xsl:attribute>
    <xsl:attribute name="padding-top">2mm</xsl:attribute>
    <xsl:attribute name="padding-bottom">2mm</xsl:attribute>
    <xsl:attribute name="border">0.25px solid #000000</xsl:attribute>
    <xsl:attribute name="background-color">#CCFFCC</xsl:attribute>
<!-- force data blocks to left for maximum display space -->
    <xsl:attribute name="start-indent">0mm</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="list" xsl:use-attribute-sets="general"/>
  <xsl:attribute-set name="list.label" xsl:use-attribute-sets="general"/>
  <xsl:attribute-set name="list.item">
    <xsl:attribute name="space-after">4pt</xsl:attribute>
    <xsl:attribute name="space-before">4pt</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="list.block" xsl:use-attribute-sets="general">
    <xsl:attribute name="provisional-distance-between-starts">5mm</xsl:attribute>
    <xsl:attribute name="provisional-label-separation">3mm</xsl:attribute>
    <xsl:attribute name="space-after">4pt</xsl:attribute>
    <xsl:attribute name="space-before">4pt</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="enum" xsl:use-attribute-sets="general"/>
  <xsl:attribute-set name="enum.label" xsl:use-attribute-sets="general"/>
  <xsl:attribute-set name="list.item">
    <xsl:attribute name="space-after">4pt</xsl:attribute>
    <xsl:attribute name="space-before">4pt</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="enum.block" xsl:use-attribute-sets="general">
    <xsl:attribute name="provisional-distance-between-starts">5mm</xsl:attribute>
    <xsl:attribute name="provisional-label-separation">3mm</xsl:attribute>
    <xsl:attribute name="space-after">4pt</xsl:attribute>
    <xsl:attribute name="space-before">4pt</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="link">
    <xsl:attribute name="color">blue</xsl:attribute>
<!-- underline not inherited in XSL-FO, fo:wrapper did not help -->
<!--    <xsl:attribute name="text-decoration">underline</xsl:attribute> -->
  </xsl:attribute-set>
<!-- page header text format -->
  <xsl:attribute-set name="standard-header">
    <xsl:attribute name="font-family">monospace</xsl:attribute>
    <xsl:attribute name="font-size">8pt</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="color">#000000</xsl:attribute>
  </xsl:attribute-set>
  <xsl:template match="/">
    <xsl:message terminate="yes">
      <xsl:text>Error: Do not call this stylesheet directly; create a new one with a root 
template creating the required XSL-FO stuff.</xsl:text>
    </xsl:message>
  </xsl:template>
<!-- page numbers and section names in header by default -->
<!-- NOTE RenderX engine doesn't like the flat list kluge I am doing here! -->
  <xsl:template name="standard-header">
    <fo:static-content flow-name="xsl-region-before">
      <fo:list-block>
        <fo:list-item>
          <fo:list-item-label>
            <fo:block text-align="left" xsl:use-attribute-sets="standard-header">
<!-- parent section for reference -->
              <fo:retrieve-marker retrieve-class-name="section" retrieve-boundary="page" retrieve-position="first-starting-within-page"/>
            </fo:block>
          </fo:list-item-label>
          <fo:list-item-body>
            <fo:block xsl:use-attribute-sets="standard-header" text-align="right">
<!-- page numbers -->
              <fo:page-number/>
              <xsl:text> / </xsl:text>
              <fo:page-number-citation ref-id="finis"/>
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </fo:list-block>
    </fo:static-content>
  </xsl:template>
  <xsl:template match="eolas">
    <xsl:message terminate="yes">
      <xsl:text>Error: </xsl:text>
      <xsl:value-of select="name()"/>
      <xsl:text>
Eolas element needs own template.</xsl:text>
    </xsl:message>
  </xsl:template>
  <xsl:template match="summary/title">
    <fo:block xsl:use-attribute-sets="general summary" font-size="24pt" font-weight="bold" id="{generate-id()}">
      <xsl:value-of select="."/>
    </fo:block>
  </xsl:template>
  <xsl:template match="summary/description">
<!--    <xsl:if test="description"> -->
    <fo:block xsl:use-attribute-sets="general summary">
      <xsl:value-of select="."/>
    </fo:block>
<!--    </xsl:if> -->
  </xsl:template>
  <xsl:template match="summary/date">
<!--    <xsl:if test="date"> -->
    <fo:block xsl:use-attribute-sets="general summary" font-size="9pt">
      <xsl:value-of select="."/>
    </fo:block>
<!--    </xsl:if> -->
  </xsl:template>
  <xsl:template match="summary/rights">
<!--    <xsl:if test="rights"> -->
    <fo:block xsl:use-attribute-sets="general summary" font-size="9pt">
      <xsl:value-of select="."/>
    </fo:block>
<!--    </xsl:if> -->
  </xsl:template>
  <xsl:template match="summary/source">
    <fo:block xsl:use-attribute-sets="general summary">
      <fo:basic-link xsl:use-attribute-sets="link" external-destination="{@xlink:href}">
        <xsl:choose>
          <xsl:when test="text()">
            <xsl:value-of select="."/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@xlink:href"/>
          </xsl:otherwise>
        </xsl:choose>
      </fo:basic-link>
    </fo:block>
  </xsl:template>
  <xsl:template match="summary/source" mode="not-summary">
    <fo:block xsl:use-attribute-sets="general">
      <fo:basic-link xsl:use-attribute-sets="link" external-destination="{@xlink:href}">
        <xsl:choose>
          <xsl:when test="text()">
            <xsl:value-of select="."/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@xlink:href"/>
          </xsl:otherwise>
        </xsl:choose>
      </fo:basic-link>
    </fo:block>
  </xsl:template>
  <xsl:template match="summary">
    <xsl:message terminate="yes">
      <xsl:text>Error: </xsl:text>
      <xsl:value-of select="name()"/>
      <xsl:text>
Summary element needs own template.</xsl:text>
    </xsl:message>
  </xsl:template>
<!-- outline (for Fop PDF Outline/Bookmarks generation) -->
  <xsl:template match="section" mode="fox-outline">
    <fox:outline internal-destination="{generate-id()}">
      <fox:label>
        <xsl:value-of select="title"/>
      </fox:label>
      <xsl:apply-templates select="section" mode="fox-outline"/>
    </fox:outline>
  </xsl:template>
  <xsl:template match="section">
    <xsl:message terminate="yes">
      <xsl:text>Error: </xsl:text>
      <xsl:value-of select="name()"/>
      <xsl:text>
Section element needs own template.</xsl:text>
    </xsl:message>
  </xsl:template>
  <xsl:template match="title">
    <fo:block xsl:use-attribute-sets="title">
<!-- set section marker to name of previous section or document title -->
      <fo:wrapper xsl:use-attribute-sets="standard-header">
        <fo:marker marker-class-name="section">
          <xsl:choose>
            <xsl:when test="count(ancestor::section) &gt;= 2">
              <xsl:value-of select="ancestor::section[position()=2]/title"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="//summary/title"/>
            </xsl:otherwise>
          </xsl:choose>
        </fo:marker>
      </fo:wrapper>
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>
<!-- lists -->
  <xsl:template match="list">
<!-- XSL-FO does not like loose recursive lists, need to
		create a invisible list item when being recursive. -->
    <xsl:choose>
      <xsl:when test="../li">
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block xsl:use-attribute-sets="list.label"/>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:list-block xsl:use-attribute-sets="list.block">
              <xsl:apply-templates/>
            </fo:list-block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:when>
      <xsl:otherwise>
        <fo:list-block xsl:use-attribute-sets="list.block">
          <xsl:apply-templates/>
        </fo:list-block>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="enum">
<!-- XSL-FO does not like loose recursive lists, need to
		create a invisible list item when being recursive. -->
    <xsl:choose>
      <xsl:when test="../li">
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block xsl:use-attribute-sets="enum.label"/>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:list-block xsl:use-attribute-sets="enum.block">
              <xsl:apply-templates/>
            </fo:list-block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:when>
      <xsl:otherwise>
        <fo:list-block xsl:use-attribute-sets="enum.block">
          <xsl:apply-templates/>
        </fo:list-block>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="li">
    <fo:list-item xsl:use-attribute-sets="list.item">
      <fo:list-item-label end-indent="label-end()">
        <fo:block xsl:use-attribute-sets="{name(ancestor::*[position()=1])}.label">
          <xsl:choose>
<!-- fun with XPath to get enumerated list -->
            <xsl:when test="name(ancestor::*[position()=1]) = 'enum'">
              <xsl:value-of select="count(preceding-sibling::li)+1"/>
              <xsl:text>.</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>•</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </fo:block>
      </fo:list-item-label>
      <fo:list-item-body start-indent="body-start()">
        <fo:block xsl:use-attribute-sets="{name(ancestor::*[position()=1])}.block">
          <xsl:apply-templates/>
        </fo:block>
      </fo:list-item-body>
    </fo:list-item>
  </xsl:template>
<!-- XSL-FO does not like loose recursive lists, need to create a invisible list item when being recursive with block elements -->
  <xsl:template match="info[../li]">
    <fo:list-item>
      <fo:list-item-label end-indent="label-end()">
        <fo:block xsl:use-attribute-sets="list.label"/>
      </fo:list-item-label>
      <fo:list-item-body start-indent="body-start()">
        <fo:block xsl:use-attribute-sets="info">
          <xsl:apply-templates/>
        </fo:block>
      </fo:list-item-body>
    </fo:list-item>
  </xsl:template>
  <xsl:template match="note[../li]">
    <fo:list-item>
      <fo:list-item-label end-indent="label-end()">
        <fo:block xsl:use-attribute-sets="list.label"/>
      </fo:list-item-label>
      <fo:list-item-body start-indent="body-start()">
        <fo:block xsl:use-attribute-sets="note">
          <xsl:apply-templates/>
        </fo:block>
      </fo:list-item-body>
    </fo:list-item>
  </xsl:template>
  <xsl:template match="warn[../li]">
    <fo:list-item>
      <fo:list-item-label end-indent="label-end()">
        <fo:block xsl:use-attribute-sets="list.label"/>
      </fo:list-item-label>
      <fo:list-item-body start-indent="body-start()">
        <fo:block xsl:use-attribute-sets="warn">
          <xsl:apply-templates/>
        </fo:block>
      </fo:list-item-body>
    </fo:list-item>
  </xsl:template>
  <xsl:template match="data[../li]">
    <fo:list-item>
      <fo:list-item-label end-indent="label-end()">
        <fo:block xsl:use-attribute-sets="list.label"/>
      </fo:list-item-label>
      <fo:list-item-body start-indent="body-start()">
        <xsl:choose>
          <xsl:when test="descendant::shell">
            <fo:block xsl:use-attribute-sets="data-shell">
              <xsl:apply-templates/>
            </fo:block>
          </xsl:when>
          <xsl:otherwise>
            <fo:block xsl:use-attribute-sets="data">
              <xsl:apply-templates/>
            </fo:block>
          </xsl:otherwise>
        </xsl:choose>
      </fo:list-item-body>
    </fo:list-item>
  </xsl:template>
<!-- various "block" textual elements; attribute-sets specify the style based on the element name, allowing overloading on the template matching -->
  <xsl:template match="info">
    <fo:block xsl:use-attribute-sets="info">
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>
  <xsl:template match="note">
    <fo:block xsl:use-attribute-sets="note">
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>
  <xsl:template match="warn">
    <fo:block xsl:use-attribute-sets="warn">
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>
  <xsl:template match="data">
    <xsl:choose>
      <xsl:when test="descendant::shell">
        <fo:block xsl:use-attribute-sets="data-shell">
          <xsl:apply-templates/>
        </fo:block>
      </xsl:when>
      <xsl:otherwise>
        <fo:block xsl:use-attribute-sets="data">
          <xsl:apply-templates/>
        </fo:block>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="line">
    <fo:block>
<!-- <line/> get eaten, so need to insert non-breaking space -->
      <xsl:choose>
        <xsl:when test="not(descendant-or-self::text())">
          <xsl:text> </xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
    </fo:block>
  </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>
        <fo:block/>
        <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">
        <fo:block/>
      </xsl:when>
      <xsl:otherwise>
        <fo:block/>
      </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>
<!-- KLUGE Fop does not implement any whitespace handling features of XSL-FO that do what I want in my testing, so need to sub spaces for non-breaking spaces to make code examples not fold significant whitespace... -->
<!-- TODO need special tab or other whitespace handling? -->
  <xsl:template match="line/text()">
    <xsl:value-of select="translate(., ' ', ' ')"/>
  </xsl:template>
  <xsl:template match="input">
    <fo:inline font-weight="bold">
      <xsl:apply-templates/>
    </fo:inline>
  </xsl:template>
  <xsl:template match="comment">
    <fo:inline color="#993300">
      <xsl:apply-templates/>
    </fo:inline>
  </xsl:template>
  <xsl:template match="shell">
    <fo:block>
      <xsl:if test="@prefix">
        <xsl:value-of select="@prefix"/>
      </xsl:if>
      <fo:inline font-weight="bold">
        <xsl:apply-templates/>
      </fo:inline>
    </fo:block>
  </xsl:template>
<!-- TODO how support inline xlink:href on these? need to? -->
  <xsl:template match="code">
    <fo:inline xsl:use-attribute-sets="computer">
      <xsl:apply-templates/>
    </fo:inline>
  </xsl:template>
  <xsl:template match="file|file-glob">
    <fo:inline color="#007a00" xsl:use-attribute-sets="computer">
      <xsl:apply-templates/>
    </fo:inline>
  </xsl:template>
  <xsl:template match="cmd|cmd-arg">
    <fo:inline color="#990033" xsl:use-attribute-sets="computer">
      <xsl:apply-templates/>
    </fo:inline>
  </xsl:template>
  <xsl:template match="em">
    <fo:inline font-style="italic" font-weight="bold">
      <xsl:apply-templates/>
    </fo:inline>
  </xsl:template>
  <xsl:template match="gui">
    <fo:inline color="#CC3300">
      <xsl:apply-templates/>
    </fo:inline>
  </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">
            <fo:basic-link xsl:use-attribute-sets="link" external-destination="{@xlink:href}">
              <xsl:value-of select="name"/>
              <xsl:text> (</xsl:text>
              <xsl:value-of select="abbr"/>
              <xsl:text>)</xsl:text>
            </fo:basic-link>
          </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">
            <fo:basic-link xsl:use-attribute-sets="link" external-destination="{@xlink:href}">
              <xsl:value-of select="abbr"/>
            </fo:basic-link>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="abbr"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="man">
    <xsl:element name="fo:basic-link" xsl:use-attribute-sets="link">
      <xsl:attribute name="external-destination">
        <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>
<!-- TODO 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>
      <fo:inline xsl:use-attribute-sets="computer">
        <xsl:value-of select="."/>
        <xsl:text>(</xsl:text>
        <xsl:value-of select="@section"/>
        <xsl:text>)</xsl:text>
      </fo:inline>
    </xsl:element>
  </xsl:template>
  <xsl:template match="perl-module">
    <xsl:element name="fo:basic-link" xsl:use-attribute-sets="link">
      <xsl:attribute name="external-destination">
        <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> -->
<!-- change ::'s into /'s -->
<!--            <xsl:value-of select="translate(normalize-space(translate(text(), ':', ' ')), ' ', '/')"/>
            <xsl:text>.html</xsl:text> -->
            <xsl:text>http://search.cpan.org/search?mode=module&amp;query=</xsl:text>
            <xsl:value-of select="text()"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <fo:inline xsl:use-attribute-sets="computer">
        <xsl:value-of select="."/>
      </fo:inline>
    </xsl:element>
  </xsl:template>
  <xsl:template match="perl-pod">
    <xsl:element name="fo:basic-link" xsl:use-attribute-sets="link">
      <xsl:attribute name="external-destination">
        <xsl:choose>
          <xsl:when test="@xlink:href">
            <xsl:value-of select="@xlink:href"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>http://www.perldoc.com/perl5.8.0/pod/</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>.html</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <fo:inline xsl:use-attribute-sets="computer">
        <xsl:value-of select="."/>
      </fo:inline>
    </xsl:element>
  </xsl:template>
  <xsl:template match="rfc">
    <fo:inline xsl:use-attribute-sets="computer">[</fo:inline>
    <xsl:element name="fo:basic-link" xsl:use-attribute-sets="link">
      <xsl:attribute name="external-destination">
        <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="."/>
            <xsl:text>.txt</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <fo:inline xsl:use-attribute-sets="computer">
        <xsl:text>RFC </xsl:text>
        <xsl:value-of select="."/>
      </fo:inline>
    </xsl:element>
    <fo:inline xsl:use-attribute-sets="computer">]</fo:inline>
  </xsl:template>
<!-- pull in images -->
  <xsl:template match="image">
    <fo:external-graphic src="{@xlink:href}"/>
  </xsl:template>
  <xsl:template match="image-svg">
    <fo:external-graphic src="{@xlink:href}" width="{document(@xlink:href)/*/@width}" height="{document(@xlink:href)/*/@height}"/>
  </xsl:template>
<!-- generate links... -->
  <xsl:template match="link">
    <fo:basic-link xsl:use-attribute-sets="link" external-destination="{@xlink:href}">
      <xsl:apply-templates/>
    </fo:basic-link>
  </xsl:template>
</xsl:stylesheet>
