1
|
<?xml version='1.0'?>
|
2
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
3
|
xmlns:exsl="http://exslt.org/common"
|
4
|
exclude-result-prefixes="exsl"
|
5
|
version='1.0'>
|
6
|
|
7
|
<!-- ********************************************************************
|
8
|
$Id: footnote.xsl 8421 2009-05-04 07:49:49Z bobstayton $
|
9
|
********************************************************************
|
10
|
|
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.
|
14
|
|
15
|
******************************************************************** -->
|
16
|
|
17
|
<xsl:template match="footnote">
|
18
|
<xsl:variable name="name">
|
19
|
<xsl:call-template name="object.id"/>
|
20
|
</xsl:variable>
|
21
|
<xsl:variable name="href">
|
22
|
<xsl:text>#ftn.</xsl:text>
|
23
|
<xsl:call-template name="object.id"/>
|
24
|
</xsl:variable>
|
25
|
|
26
|
<xsl:choose>
|
27
|
<xsl:when test="ancestor::tgroup">
|
28
|
<sup>
|
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"/>
|
33
|
</a>
|
34
|
<xsl:text>]</xsl:text>
|
35
|
</sup>
|
36
|
</xsl:when>
|
37
|
<xsl:otherwise>
|
38
|
<sup>
|
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"/>
|
43
|
</a>
|
44
|
<xsl:text>]</xsl:text>
|
45
|
</sup>
|
46
|
</xsl:otherwise>
|
47
|
</xsl:choose>
|
48
|
</xsl:template>
|
49
|
|
50
|
<xsl:template match="footnoteref">
|
51
|
<xsl:variable name="targets" select="key('id',@linkend)"/>
|
52
|
<xsl:variable name="footnote" select="$targets[1]"/>
|
53
|
|
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"/>
|
60
|
</xsl:message>
|
61
|
</xsl:if>
|
62
|
|
63
|
<xsl:variable name="target.href">
|
64
|
<xsl:call-template name="href.target">
|
65
|
<xsl:with-param name="object" select="$footnote"/>
|
66
|
</xsl:call-template>
|
67
|
</xsl:variable>
|
68
|
|
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, '#')"/>
|
73
|
</xsl:variable>
|
74
|
|
75
|
<sup>
|
76
|
<xsl:text>[</xsl:text>
|
77
|
<a href="{$href}">
|
78
|
<xsl:apply-templates select="." mode="class.attribute"/>
|
79
|
<xsl:apply-templates select="$footnote" mode="footnote.number"/>
|
80
|
</a>
|
81
|
<xsl:text>]</xsl:text>
|
82
|
</sup>
|
83
|
</xsl:template>
|
84
|
|
85
|
<xsl:template match="footnote" mode="footnote.number">
|
86
|
<xsl:choose>
|
87
|
<xsl:when test="string-length(@label) != 0">
|
88
|
<xsl:value-of select="@label"/>
|
89
|
</xsl:when>
|
90
|
<xsl:when test="ancestor::tgroup">
|
91
|
<xsl:variable name="tfnum">
|
92
|
<xsl:number level="any" from="table|informaltable" format="1"/>
|
93
|
</xsl:variable>
|
94
|
|
95
|
<xsl:choose>
|
96
|
<xsl:when test="string-length($table.footnote.number.symbols) >= $tfnum">
|
97
|
<xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/>
|
98
|
</xsl:when>
|
99
|
<xsl:otherwise>
|
100
|
<xsl:number level="any" from="tgroup"
|
101
|
format="{$table.footnote.number.format}"/>
|
102
|
</xsl:otherwise>
|
103
|
</xsl:choose>
|
104
|
</xsl:when>
|
105
|
<xsl:otherwise>
|
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"/>
|
109
|
|
110
|
<xsl:choose>
|
111
|
<xsl:when test="string-length($footnote.number.symbols) >= $fnum">
|
112
|
<xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
|
113
|
</xsl:when>
|
114
|
<xsl:otherwise>
|
115
|
<xsl:number value="$fnum" format="{$footnote.number.format}"/>
|
116
|
</xsl:otherwise>
|
117
|
</xsl:choose>
|
118
|
</xsl:otherwise>
|
119
|
</xsl:choose>
|
120
|
</xsl:template>
|
121
|
|
122
|
<!-- ==================================================================== -->
|
123
|
|
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"/>
|
131
|
</xsl:call-template>
|
132
|
</xsl:variable>
|
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"/>
|
137
|
</xsl:call-template>
|
138
|
</xsl:variable>
|
139
|
<p>
|
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>
|
145
|
</xsl:if>
|
146
|
<sup>
|
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"/>
|
152
|
</a>
|
153
|
<xsl:text>] </xsl:text>
|
154
|
</sup>
|
155
|
<xsl:apply-templates/>
|
156
|
</p>
|
157
|
</xsl:template>
|
158
|
|
159
|
<!-- ==================================================================== -->
|
160
|
|
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"/>
|
166
|
</xsl:call-template>
|
167
|
</xsl:variable>
|
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"/>
|
172
|
</xsl:call-template>
|
173
|
</xsl:variable>
|
174
|
<xsl:variable name="footnote.mark">
|
175
|
<sup>
|
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"/>
|
181
|
</a>
|
182
|
<xsl:text>] </xsl:text>
|
183
|
</sup>
|
184
|
</xsl:variable>
|
185
|
|
186
|
<xsl:variable name="html">
|
187
|
<xsl:apply-templates select="."/>
|
188
|
</xsl:variable>
|
189
|
|
190
|
<xsl:choose>
|
191
|
<xsl:when test="$exsl.node.set.available != 0">
|
192
|
<xsl:variable name="html-nodes" select="exsl:node-set($html)"/>
|
193
|
<xsl:choose>
|
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>
|
198
|
</xsl:when>
|
199
|
<xsl:otherwise>
|
200
|
<xsl:apply-templates select="$html-nodes" mode="insert.html.text">
|
201
|
<xsl:with-param name="mark" select="$footnote.mark"/>
|
202
|
</xsl:apply-templates>
|
203
|
</xsl:otherwise>
|
204
|
</xsl:choose>
|
205
|
</xsl:when>
|
206
|
<xsl:otherwise>
|
207
|
<xsl:copy-of select="$html"/>
|
208
|
</xsl:otherwise>
|
209
|
</xsl:choose>
|
210
|
</xsl:template>
|
211
|
|
212
|
<!-- ==================================================================== -->
|
213
|
|
214
|
<!--
|
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)]"/>
|
221
|
|
222
|
<xsl:choose>
|
223
|
<xsl:when test="not($list)">
|
224
|
<xsl:text>-1</xsl:text>
|
225
|
</xsl:when>
|
226
|
<xsl:when test="$list[1] = $to">
|
227
|
<xsl:value-of select="$count + 1"/>
|
228
|
</xsl:when>
|
229
|
<xsl:otherwise>
|
230
|
</xsl:otherwise>
|
231
|
</xsl:choose>
|
232
|
</xsl:template>
|
233
|
-->
|
234
|
|
235
|
<!-- ==================================================================== -->
|
236
|
|
237
|
<xsl:template name="process.footnotes">
|
238
|
<xsl:variable name="footnotes" select=".//footnote"/>
|
239
|
<xsl:variable name="table.footnotes"
|
240
|
select=".//tgroup//footnote"/>
|
241
|
|
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">
|
245
|
<br/>
|
246
|
<hr width="100" align="{$direction.align.start}"/>
|
247
|
<xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/>
|
248
|
</div>
|
249
|
</xsl:if>
|
250
|
|
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>
|
257
|
</div>
|
258
|
|
259
|
<xsl:apply-templates select="//annotation"
|
260
|
mode="annotation-popup"/>
|
261
|
</div>
|
262
|
</xsl:if>
|
263
|
</xsl:template>
|
264
|
|
265
|
<xsl:template name="process.chunk.footnotes">
|
266
|
<!-- nop -->
|
267
|
</xsl:template>
|
268
|
|
269
|
<xsl:template match="footnote" name="process.footnote" mode="process.footnote.mode">
|
270
|
<xsl:choose>
|
271
|
<xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
|
272
|
<div>
|
273
|
<xsl:call-template name="common.html.attributes"/>
|
274
|
<xsl:apply-templates/>
|
275
|
</div>
|
276
|
</xsl:when>
|
277
|
|
278
|
<xsl:when test="$html.cleanup != 0 and
|
279
|
$exsl.node.set.available != 0">
|
280
|
<div>
|
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]"/>
|
284
|
</div>
|
285
|
</xsl:when>
|
286
|
|
287
|
<xsl:otherwise>
|
288
|
<xsl:message>
|
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>
|
293
|
</xsl:message>
|
294
|
<div>
|
295
|
<xsl:call-template name="common.html.attributes"/>
|
296
|
<xsl:apply-templates/>
|
297
|
</div>
|
298
|
</xsl:otherwise>
|
299
|
</xsl:choose>
|
300
|
</xsl:template>
|
301
|
|
302
|
<xsl:template match="tgroup//footnote"
|
303
|
mode="process.footnote.mode">
|
304
|
</xsl:template>
|
305
|
|
306
|
<xsl:template match="footnote" mode="table.footnote.mode">
|
307
|
<xsl:call-template name="process.footnote"/>
|
308
|
</xsl:template>
|
309
|
|
310
|
</xsl:stylesheet>
|