link: Added example.xml and footnote style sheets
authorFredrik Unger <fred@tree.se>
Wed, 31 Jul 2013 08:59:37 +0000 (10:59 +0200)
committerFredrik Unger <fred@tree.se>
Wed, 31 Jul 2013 08:59:37 +0000 (10:59 +0200)
Simple example file showing a link tag. Style sheet for html and
pdf (fo) that takes the link URL and puts it as a footnote.

link/example.xml [new file with mode: 0644]
link/footnote.html.xsl [new file with mode: 0644]
link/footnote.pdf.xsl [new file with mode: 0644]

diff --git a/link/example.xml b/link/example.xml
new file mode 100644 (file)
index 0000000..865ecb8
--- /dev/null
@@ -0,0 +1,43 @@
+<?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>
diff --git a/link/footnote.html.xsl b/link/footnote.html.xsl
new file mode 100644 (file)
index 0000000..a1f41e1
--- /dev/null
@@ -0,0 +1,110 @@
+<?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) &gt;= $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) &gt;= $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>
diff --git a/link/footnote.pdf.xsl b/link/footnote.pdf.xsl
new file mode 100644 (file)
index 0000000..a4cbfb4
--- /dev/null
@@ -0,0 +1,13 @@
+<?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:fo="http://www.w3.org/1999/XSL/Format">
+
+<!-- Fredrik Unger <fred@tree.se>  -->
+
+<xsl:import href="../default.pdf.xsl"/>
+<xsl:param name="ulink.footnotes" select="1"/>
+<xsl:param name="ulink.show" select="1"/>
+
+</xsl:stylesheet>