2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:exsl="http://exslt.org/common"
4 exclude-result-prefixes="exsl"
7 <!-- ********************************************************************
8 $Id: footnote.xsl 8812 2010-08-09 20:51:51Z bobstayton $
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://docbook.sf.net/release/xsl/current/ for
13 copyright and other information.
15 ******************************************************************** -->
17 <xsl:template match="footnote">
18 <xsl:variable name="name">
19 <xsl:call-template name="object.id"/>
21 <xsl:variable name="href">
22 <xsl:text>#ftn.</xsl:text>
23 <xsl:call-template name="object.id"/>
27 <xsl:when test="ancestor::table or ancestor::informaltable">
29 <xsl:text>[</xsl:text>
30 <a name="{$name}" href="{$href}">
31 <xsl:apply-templates select="." mode="class.attribute"/>
32 <xsl:apply-templates select="." mode="footnote.number"/>
34 <xsl:text>]</xsl:text>
39 <xsl:text>[</xsl:text>
40 <a name="{$name}" href="{$href}">
41 <xsl:apply-templates select="." mode="class.attribute"/>
42 <xsl:apply-templates select="." mode="footnote.number"/>
44 <xsl:text>]</xsl:text>
50 <xsl:template match="footnoteref">
51 <xsl:variable name="targets" select="key('id',@linkend)"/>
52 <xsl:variable name="footnote" select="$targets[1]"/>
54 <xsl:if test="not(local-name($footnote) = 'footnote')">
55 <xsl:message terminate="yes">
56 ERROR: A footnoteref element has a linkend that points to an element that is not a footnote.
57 Typically this happens when an id attribute is accidentally applied to the child of a footnote element.
58 target element: <xsl:value-of select="local-name($footnote)"/>
59 linkend/id: <xsl:value-of select="@linkend"/>
63 <xsl:variable name="target.href">
64 <xsl:call-template name="href.target">
65 <xsl:with-param name="object" select="$footnote"/>
69 <xsl:variable name="href">
70 <xsl:value-of select="substring-before($target.href, '#')"/>
71 <xsl:text>#ftn.</xsl:text>
72 <xsl:value-of select="substring-after($target.href, '#')"/>
76 <xsl:text>[</xsl:text>
78 <xsl:apply-templates select="." mode="class.attribute"/>
79 <xsl:apply-templates select="$footnote" mode="footnote.number"/>
81 <xsl:text>]</xsl:text>
85 <xsl:template match="footnote" mode="footnote.number">
87 <xsl:when test="string-length(@label) != 0">
88 <xsl:value-of select="@label"/>
90 <xsl:when test="ancestor::table or ancestor::informaltable">
91 <xsl:variable name="tfnum">
92 <xsl:number level="any" from="table|informaltable" format="1"/>
96 <xsl:when test="string-length($table.footnote.number.symbols) >= $tfnum">
97 <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/>
100 <xsl:number level="any" from="table | informaltable"
101 format="{$table.footnote.number.format}"/>
106 <xsl:variable name="pfoot" select="preceding::footnote[not(@label)]"/>
107 <xsl:variable name="ptfoot" select="preceding::table//footnote |
108 preceding::informaltable//footnote"/>
109 <xsl:variable name="fnum" select="count($pfoot) - count($ptfoot) + 1"/>
112 <xsl:when test="string-length($footnote.number.symbols) >= $fnum">
113 <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
116 <xsl:number value="$fnum" format="{$footnote.number.format}"/>
123 <!-- ==================================================================== -->
125 <xsl:template match="footnote/para[1]|footnote/simpara[1]" priority="2">
126 <!-- this only works if the first thing in a footnote is a para, -->
127 <!-- which is ok, because it usually is. -->
128 <xsl:variable name="name">
129 <xsl:text>ftn.</xsl:text>
130 <xsl:call-template name="object.id">
131 <xsl:with-param name="object" select="ancestor::footnote"/>
134 <xsl:variable name="href">
135 <xsl:text>#</xsl:text>
136 <xsl:call-template name="object.id">
137 <xsl:with-param name="object" select="ancestor::footnote"/>
141 <xsl:call-template name="paragraph">
142 <xsl:with-param name="class">
143 <xsl:if test="@role and $para.propagates.style != 0">
144 <xsl:value-of select="@role"/>
147 <xsl:with-param name="content">
149 <xsl:text>[</xsl:text>
150 <a id="{$name}" href="{$href}">
151 <xsl:apply-templates select="." mode="class.attribute"/>
152 <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
154 <xsl:text>] </xsl:text>
156 <xsl:apply-templates/>
162 <!-- ==================================================================== -->
164 <xsl:template match="*" mode="footnote.body.number">
165 <xsl:variable name="name">
166 <xsl:text>ftn.</xsl:text>
167 <xsl:call-template name="object.id">
168 <xsl:with-param name="object" select="ancestor::footnote"/>
171 <xsl:variable name="href">
172 <xsl:text>#</xsl:text>
173 <xsl:call-template name="object.id">
174 <xsl:with-param name="object" select="ancestor::footnote"/>
177 <xsl:variable name="footnote.mark">
179 <xsl:text>[</xsl:text>
180 <a name="{$name}" href="{$href}">
181 <xsl:apply-templates select="." mode="class.attribute"/>
182 <xsl:apply-templates select="ancestor::footnote"
183 mode="footnote.number"/>
185 <xsl:text>] </xsl:text>
189 <xsl:variable name="html">
190 <xsl:apply-templates select="."/>
194 <xsl:when test="$exsl.node.set.available != 0">
195 <xsl:variable name="html-nodes" select="exsl:node-set($html)"/>
197 <xsl:when test="$html-nodes//p">
198 <xsl:apply-templates select="$html-nodes" mode="insert.html.p">
199 <xsl:with-param name="mark" select="$footnote.mark"/>
200 </xsl:apply-templates>
203 <xsl:apply-templates select="$html-nodes" mode="insert.html.text">
204 <xsl:with-param name="mark" select="$footnote.mark"/>
205 </xsl:apply-templates>
210 <xsl:copy-of select="$html"/>
215 <!-- ==================================================================== -->
218 <xsl:template name="count-element-from">
219 <xsl:param name="from" select=".."/>
220 <xsl:param name="to" select="."/>
221 <xsl:param name="count" select="0"/>
222 <xsl:param name="list" select="$from/following::*[local-name(.)=local-name($to)]
223 |$from/descendant-or-self::*[local-name(.)=local-name($to)]"/>
226 <xsl:when test="not($list)">
227 <xsl:text>-1</xsl:text>
229 <xsl:when test="$list[1] = $to">
230 <xsl:value-of select="$count + 1"/>
238 <!-- ==================================================================== -->
240 <xsl:template name="process.footnotes">
241 <xsl:variable name="footnotes" select=".//footnote"/>
242 <xsl:variable name="table.footnotes"
243 select=".//table//footnote | .//informaltable//footnote"/>
245 <!-- Only bother to do this if there's at least one non-table footnote -->
246 <xsl:if test="count($footnotes)>count($table.footnotes)">
247 <div class="footnotes">
249 <hr width="100" align="{$direction.align.start}"/>
250 <xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/>
254 <xsl:if test="$annotation.support != 0 and //annotation">
255 <div class="annotation-list">
256 <div class="annotation-nocss">
257 <p>The following annotations are from this essay. You are seeing
258 them here because your browser doesn’t support the user-interface
259 techniques used to make them appear as ‘popups’ on modern browsers.</p>
262 <xsl:apply-templates select="//annotation"
263 mode="annotation-popup"/>
268 <xsl:template name="process.chunk.footnotes">
272 <xsl:template match="footnote" name="process.footnote" mode="process.footnote.mode">
274 <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
276 <xsl:call-template name="common.html.attributes"/>
277 <xsl:apply-templates/>
281 <xsl:when test="$html.cleanup != 0 and
282 $exsl.node.set.available != 0">
284 <xsl:call-template name="common.html.attributes"/>
285 <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
286 <xsl:apply-templates select="*[position() > 1]"/>
292 <xsl:text>Warning: footnote number may not be generated </xsl:text>
293 <xsl:text>correctly; </xsl:text>
294 <xsl:value-of select="local-name(*[1])"/>
295 <xsl:text> unexpected as first child of footnote.</xsl:text>
298 <xsl:call-template name="common.html.attributes"/>
299 <xsl:apply-templates/>
305 <xsl:template match="table//footnote | informaltable//footnote"
306 mode="process.footnote.mode">
309 <xsl:template match="footnote" mode="table.footnote.mode">
310 <xsl:call-template name="process.footnote"/>