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 8421 2009-05-04 07:49:49Z 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::tgroup">
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::tgroup">
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="tgroup"
101 format="{$table.footnote.number.format}"/>
106 <xsl:variable name="pfoot" select="preceding::footnote[not(@label)]"/>
107 <xsl:variable name="ptfoot" select="preceding::tgroup//footnote"/>
108 <xsl:variable name="fnum" select="count($pfoot) - count($ptfoot) + 1"/>
111 <xsl:when test="string-length($footnote.number.symbols) >= $fnum">
112 <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
115 <xsl:number value="$fnum" format="{$footnote.number.format}"/>
122 <!-- ==================================================================== -->
124 <xsl:template match="footnote/para[1]|footnote/simpara[1]" priority="2">
125 <!-- this only works if the first thing in a footnote is a para, -->
126 <!-- which is ok, because it usually is. -->
127 <xsl:variable name="name">
128 <xsl:text>ftn.</xsl:text>
129 <xsl:call-template name="object.id">
130 <xsl:with-param name="object" select="ancestor::footnote"/>
133 <xsl:variable name="href">
134 <xsl:text>#</xsl:text>
135 <xsl:call-template name="object.id">
136 <xsl:with-param name="object" select="ancestor::footnote"/>
140 <xsl:call-template name="locale.html.attributes"/>
141 <xsl:if test="@role and $para.propagates.style != 0">
142 <xsl:apply-templates select="." mode="class.attribute">
143 <xsl:with-param name="class" select="@role"/>
144 </xsl:apply-templates>
147 <xsl:text>[</xsl:text>
148 <a name="{$name}" href="{$href}">
149 <xsl:apply-templates select="." mode="class.attribute"/>
150 <xsl:apply-templates select="ancestor::footnote"
151 mode="footnote.number"/>
153 <xsl:text>] </xsl:text>
155 <xsl:apply-templates/>
159 <!-- ==================================================================== -->
161 <xsl:template match="*" mode="footnote.body.number">
162 <xsl:variable name="name">
163 <xsl:text>ftn.</xsl:text>
164 <xsl:call-template name="object.id">
165 <xsl:with-param name="object" select="ancestor::footnote"/>
168 <xsl:variable name="href">
169 <xsl:text>#</xsl:text>
170 <xsl:call-template name="object.id">
171 <xsl:with-param name="object" select="ancestor::footnote"/>
174 <xsl:variable name="footnote.mark">
176 <xsl:text>[</xsl:text>
177 <a name="{$name}" href="{$href}">
178 <xsl:apply-templates select="." mode="class.attribute"/>
179 <xsl:apply-templates select="ancestor::footnote"
180 mode="footnote.number"/>
182 <xsl:text>] </xsl:text>
186 <xsl:variable name="html">
187 <xsl:apply-templates select="."/>
191 <xsl:when test="$exsl.node.set.available != 0">
192 <xsl:variable name="html-nodes" select="exsl:node-set($html)"/>
194 <xsl:when test="$html-nodes//p">
195 <xsl:apply-templates select="$html-nodes" mode="insert.html.p">
196 <xsl:with-param name="mark" select="$footnote.mark"/>
197 </xsl:apply-templates>
200 <xsl:apply-templates select="$html-nodes" mode="insert.html.text">
201 <xsl:with-param name="mark" select="$footnote.mark"/>
202 </xsl:apply-templates>
207 <xsl:copy-of select="$html"/>
212 <!-- ==================================================================== -->
215 <xsl:template name="count-element-from">
216 <xsl:param name="from" select=".."/>
217 <xsl:param name="to" select="."/>
218 <xsl:param name="count" select="0"/>
219 <xsl:param name="list" select="$from/following::*[local-name(.)=local-name($to)]
220 |$from/descendant-or-self::*[local-name(.)=local-name($to)]"/>
223 <xsl:when test="not($list)">
224 <xsl:text>-1</xsl:text>
226 <xsl:when test="$list[1] = $to">
227 <xsl:value-of select="$count + 1"/>
235 <!-- ==================================================================== -->
237 <xsl:template name="process.footnotes">
238 <xsl:variable name="footnotes" select=".//footnote"/>
239 <xsl:variable name="table.footnotes"
240 select=".//tgroup//footnote"/>
242 <!-- Only bother to do this if there's at least one non-table footnote -->
243 <xsl:if test="count($footnotes)>count($table.footnotes)">
244 <div class="footnotes">
246 <hr width="100" align="{$direction.align.start}"/>
247 <xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/>
251 <xsl:if test="$annotation.support != 0 and //annotation">
252 <div class="annotation-list">
253 <div class="annotation-nocss">
254 <p>The following annotations are from this essay. You are seeing
255 them here because your browser doesn’t support the user-interface
256 techniques used to make them appear as ‘popups’ on modern browsers.</p>
259 <xsl:apply-templates select="//annotation"
260 mode="annotation-popup"/>
265 <xsl:template name="process.chunk.footnotes">
269 <xsl:template match="footnote" name="process.footnote" mode="process.footnote.mode">
271 <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
273 <xsl:call-template name="common.html.attributes"/>
274 <xsl:apply-templates/>
278 <xsl:when test="$html.cleanup != 0 and
279 $exsl.node.set.available != 0">
281 <xsl:call-template name="common.html.attributes"/>
282 <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
283 <xsl:apply-templates select="*[position() > 1]"/>
289 <xsl:text>Warning: footnote number may not be generated </xsl:text>
290 <xsl:text>correctly; </xsl:text>
291 <xsl:value-of select="local-name(*[1])"/>
292 <xsl:text> unexpected as first child of footnote.</xsl:text>
295 <xsl:call-template name="common.html.attributes"/>
296 <xsl:apply-templates/>
302 <xsl:template match="tgroup//footnote"
303 mode="process.footnote.mode">
306 <xsl:template match="footnote" mode="table.footnote.mode">
307 <xsl:call-template name="process.footnote"/>