--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<article version="5.0" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <info>
+ <title>Making a link a footnote</title>
+ <titleabbrev>Linkfootnote</titleabbrev>
+ <author>
+ <personname>
+ <honorific>Mr</honorific>
+ <firstname>Fredrik</firstname>
+ <surname>Unger</surname>
+ </personname>
+ <email>fred@tree.se</email>
+ <affiliation>
+ <orgname>Tree.se</orgname>
+ </affiliation>
+ </author>
+ <pubdate>2013-07-29</pubdate>
+ <abstract>
+ <para>
+ Displaying a link as a footnote instead of the default in
+ text representation.
+ </para>
+ </abstract>
+ </info>
+ <section><title>Example code</title>
+ <para>
+ Sometimes a link in the text to a website is better not
+ interspersed in the text as the default processing but put as a
+ footnote. This makes the text easier to read but still providing
+ the link. By using overloading the style sheet the docbook xml can
+ be kept the same.
+ </para>
+ <para>
+ There is a <link xlink:href="http://example.com">domain</link>
+ that is established to be used for illustrative examples in
+ documents. One can use this domain in examples without prior
+ coordination or asking for permission.
+ </para>
+ </section>
+</article>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:d="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+
+<!-- Fredrik Unger <fred@tree.se> -->
+
+<xsl:import href="../default.html.xsl"/>
+
+<xsl:template match="d:link">
+ <xsl:variable name="name">
+ <xsl:call-template name="object.id"/>
+ </xsl:variable>
+ <xsl:variable name="href">
+ <xsl:text>#ftn.</xsl:text>
+ <xsl:call-template name="object.id"/>
+ </xsl:variable>
+ <xsl:apply-templates mode="no.anchor.mode"/>
+ <sup>
+ <xsl:text>[</xsl:text>
+ <a name="{$name}" href="{$href}">
+ <xsl:apply-templates select="." mode="class.attribute"/>
+ <xsl:apply-templates select="." mode="footnote.number"/>
+ </a>
+ <xsl:text>]</xsl:text>
+ </sup>
+</xsl:template>
+
+<xsl:template match="d:link" mode="footnote.number">
+ <xsl:choose>
+ <xsl:when test="string-length(@label) != 0">
+ <xsl:value-of select="@label"/>
+ </xsl:when>
+ <xsl:when test="ancestor::d:table or ancestor::d:informaltable">
+ <xsl:variable name="tfnum">
+ <xsl:number level="any" from="d:table|d:informaltable" format="1"/>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="string-length($table.footnote.number.symbols) >= $tfnum">
+ <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:number level="any" from="d:table | d:informaltable"
+ format="{$table.footnote.number.format}"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="pfoot" select="preceding::d:footnote[not(@label)]"/>
+ <xsl:variable name="ptfoot" select="preceding::d:table//d:footnote |
+ preceding::d:informaltable//d:footnote"/>
+ <xsl:variable name="fnum" select="count($pfoot) - count($ptfoot) + 1"/>
+
+ <xsl:choose>
+ <xsl:when test="string-length($footnote.number.symbols) >= $fnum">
+ <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:number value="$fnum" format="{$footnote.number.format}"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+<xsl:template name="process.footnotes">
+ <xsl:variable name="footnotes" select=".//d:footnote | .//d:link"/>
+ <xsl:variable name="table.footnotes"
+ select=".//d:table//d:footnote | .//d:informaltable//d:footnote"/>
+
+ <!-- Only bother to do this if there's at least one non-table footnote -->
+ <xsl:if test="count($footnotes)>count($table.footnotes)">
+ <div class="footnotes">
+ <br/>
+ <hr width="100" align="{$direction.align.start}"/>
+ <xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/>
+ </div>
+ </xsl:if>
+
+ <xsl:if test="$annotation.support != 0 and //d:annotation">
+ <div class="annotation-list">
+ <div class="annotation-nocss">
+ <p>The following annotations are from this essay. You are seeing
+ them here because your browser doesn’t support the user-interface
+ techniques used to make them appear as ‘popups’ on modern browsers.</p>
+ </div>
+
+ <xsl:apply-templates select="//d:annotation"
+ mode="annotation-popup"/>
+ </div>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="d:link" name="process.footnote" mode="process.footnote.mode">
+ <div>
+ <xsl:call-template name="common.html.attributes"/>
+ <xsl:variable name="href" select="./@xlink:href"/>
+ <xsl:text>[</xsl:text>
+ <xsl:apply-templates select="." mode="footnote.number"/>
+ <xsl:text>] </xsl:text>
+ <a href="{$href}"><xsl:value-of select="./@xlink:href"/></a>
+ </div>
+</xsl:template>
+
+<xsl:template match="d:link" mode="table.footnote.mode">
+ <xsl:call-template name="process.footnote"/>
+</xsl:template>
+
+</xsl:stylesheet>