link: Added example.xml and footnote style sheets
[docpond.git] / link / footnote.html.xsl
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>