OLD | NEW |
| (Empty) |
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 9665 2012-11-08 14:26:20Z kosek $ | |
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 <!-- This template generates just the footnote marker inline. | |
18 The footnote text is handled in name="process.footnote". | |
19 The footnote marker gets an id of @id, while the | |
20 footnote text gets an id of #ftn.@id. They cross link to each other. --> | |
21 <xsl:template match="footnote"> | |
22 <xsl:variable name="name"> | |
23 <xsl:call-template name="object.id"> | |
24 <xsl:with-param name="conditional" select="0"/> | |
25 </xsl:call-template> | |
26 </xsl:variable> | |
27 <xsl:variable name="href"> | |
28 <xsl:text>#ftn.</xsl:text> | |
29 <xsl:value-of select="$name"/> | |
30 </xsl:variable> | |
31 | |
32 <a href="{$href}"> | |
33 <xsl:apply-templates select="." mode="class.attribute"/> | |
34 <xsl:if test="$generate.id.attributes = 0"> | |
35 <xsl:attribute name="name"> | |
36 <xsl:value-of select="$name"/> | |
37 </xsl:attribute> | |
38 </xsl:if> | |
39 | |
40 <sup> | |
41 <xsl:apply-templates select="." mode="class.attribute"/> | |
42 <xsl:call-template name="id.attribute"> | |
43 <xsl:with-param name="conditional" select="0"/> | |
44 </xsl:call-template> | |
45 <xsl:text>[</xsl:text> | |
46 <xsl:apply-templates select="." mode="footnote.number"/> | |
47 <xsl:text>]</xsl:text> | |
48 </sup> | |
49 </a> | |
50 </xsl:template> | |
51 | |
52 <xsl:template match="footnoteref"> | |
53 <xsl:variable name="targets" select="key('id',@linkend)"/> | |
54 <xsl:variable name="footnote" select="$targets[1]"/> | |
55 | |
56 <xsl:if test="not(local-name($footnote) = 'footnote')"> | |
57 <xsl:message terminate="yes"> | |
58 ERROR: A footnoteref element has a linkend that points to an element that is not
a footnote. | |
59 Typically this happens when an id attribute is accidentally applied to the child
of a footnote element. | |
60 target element: <xsl:value-of select="local-name($footnote)"/> | |
61 linkend/id: <xsl:value-of select="@linkend"/> | |
62 </xsl:message> | |
63 </xsl:if> | |
64 | |
65 <xsl:variable name="target.href"> | |
66 <xsl:call-template name="href.target"> | |
67 <xsl:with-param name="object" select="$footnote"/> | |
68 </xsl:call-template> | |
69 </xsl:variable> | |
70 | |
71 <xsl:variable name="href"> | |
72 <xsl:value-of select="substring-before($target.href, '#')"/> | |
73 <xsl:text>#ftn.</xsl:text> | |
74 <xsl:value-of select="substring-after($target.href, '#')"/> | |
75 </xsl:variable> | |
76 | |
77 <a href="{$href}"> | |
78 <xsl:apply-templates select="." mode="class.attribute"/> | |
79 <xsl:call-template name="id.attribute"/> | |
80 <sup> | |
81 <xsl:apply-templates select="." mode="class.attribute"/> | |
82 <xsl:text>[</xsl:text> | |
83 <xsl:apply-templates select="$footnote" mode="footnote.number"/> | |
84 <xsl:text>]</xsl:text> | |
85 </sup> | |
86 </a> | |
87 </xsl:template> | |
88 | |
89 <xsl:template match="footnote" mode="footnote.number"> | |
90 <xsl:choose> | |
91 <xsl:when test="string-length(@label) != 0"> | |
92 <xsl:value-of select="@label"/> | |
93 </xsl:when> | |
94 <xsl:when test="ancestor::table or ancestor::informaltable"> | |
95 <xsl:variable name="tfnum"> | |
96 <xsl:number level="any" from="table|informaltable" format="1"/> | |
97 </xsl:variable> | |
98 | |
99 <xsl:choose> | |
100 <xsl:when test="string-length($table.footnote.number.symbols) >= $tfn
um"> | |
101 <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum
, 1)"/> | |
102 </xsl:when> | |
103 <xsl:otherwise> | |
104 <xsl:number level="any" from="table | informaltable" | |
105 format="{$table.footnote.number.format}"/> | |
106 </xsl:otherwise> | |
107 </xsl:choose> | |
108 </xsl:when> | |
109 <xsl:otherwise> | |
110 <xsl:variable name="pfoot" select="preceding::footnote[not(@label)]"/> | |
111 <xsl:variable name="ptfoot" select="preceding::table//footnote | | |
112 preceding::informaltable//footnote"/> | |
113 <xsl:variable name="fnum" select="count($pfoot) - count($ptfoot) + 1"/> | |
114 | |
115 <xsl:choose> | |
116 <xsl:when test="string-length($footnote.number.symbols) >= $fnum"> | |
117 <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/> | |
118 </xsl:when> | |
119 <xsl:otherwise> | |
120 <xsl:number value="$fnum" format="{$footnote.number.format}"/> | |
121 </xsl:otherwise> | |
122 </xsl:choose> | |
123 </xsl:otherwise> | |
124 </xsl:choose> | |
125 </xsl:template> | |
126 | |
127 <!-- ==================================================================== --> | |
128 | |
129 <xsl:template match="footnote/para[1]|footnote/simpara[1]" priority="2"> | |
130 <!-- this only works if the first thing in a footnote is a para, --> | |
131 <!-- which is ok, because it usually is. --> | |
132 <xsl:variable name="href"> | |
133 <xsl:text>#</xsl:text> | |
134 <xsl:call-template name="object.id"> | |
135 <xsl:with-param name="object" select="ancestor::footnote"/> | |
136 </xsl:call-template> | |
137 </xsl:variable> | |
138 | |
139 <xsl:call-template name="paragraph"> | |
140 <xsl:with-param name="class"> | |
141 <xsl:if test="@role and $para.propagates.style != 0"> | |
142 <xsl:value-of select="@role"/> | |
143 </xsl:if> | |
144 </xsl:with-param> | |
145 <xsl:with-param name="content"> | |
146 <a href="{$href}"> | |
147 <xsl:apply-templates select="." mode="class.attribute"/> | |
148 <sup> | |
149 <xsl:apply-templates select="." mode="class.attribute"/> | |
150 <xsl:text>[</xsl:text> | |
151 <xsl:apply-templates select="ancestor::footnote" mode="footnote.number
"/> | |
152 <xsl:text>] </xsl:text> | |
153 </sup> | |
154 </a> | |
155 <xsl:apply-templates/> | |
156 </xsl:with-param> | |
157 </xsl:call-template> | |
158 | |
159 </xsl:template> | |
160 | |
161 <!-- ==================================================================== --> | |
162 | |
163 <xsl:template match="*" mode="footnote.body.number"> | |
164 <xsl:variable name="name"> | |
165 <xsl:text>ftn.</xsl:text> | |
166 <xsl:call-template name="object.id"> | |
167 <xsl:with-param name="object" select="ancestor::footnote"/> | |
168 </xsl:call-template> | |
169 </xsl:variable> | |
170 <xsl:variable name="href"> | |
171 <xsl:text>#</xsl:text> | |
172 <xsl:call-template name="object.id"> | |
173 <xsl:with-param name="object" select="ancestor::footnote"/> | |
174 </xsl:call-template> | |
175 </xsl:variable> | |
176 <xsl:variable name="footnote.mark"> | |
177 <a href="{$href}"> | |
178 <xsl:apply-templates select="." mode="class.attribute"/> | |
179 <xsl:choose> | |
180 <xsl:when test="$generate.id.attributes = 0"> | |
181 <xsl:if test="@id or @xml:id"> | |
182 <xsl:attribute name="name"> | |
183 <xsl:value-of select="@id|@xml:id"/> | |
184 </xsl:attribute> | |
185 </xsl:if> | |
186 </xsl:when> | |
187 <xsl:otherwise> | |
188 <xsl:call-template name="id.attribute"/> | |
189 </xsl:otherwise> | |
190 </xsl:choose> | |
191 <sup> | |
192 <xsl:text>[</xsl:text> | |
193 <xsl:apply-templates select="ancestor::footnote" | |
194 mode="footnote.number"/> | |
195 <xsl:text>] </xsl:text> | |
196 </sup> | |
197 </a> | |
198 </xsl:variable> | |
199 | |
200 <xsl:variable name="html"> | |
201 <xsl:apply-templates select="."/> | |
202 </xsl:variable> | |
203 | |
204 <xsl:choose> | |
205 <xsl:when test="$exsl.node.set.available != 0"> | |
206 <xsl:variable name="html-nodes" select="exsl:node-set($html)"/> | |
207 <xsl:choose> | |
208 <xsl:when test="$html-nodes//p"> | |
209 <xsl:apply-templates select="$html-nodes" mode="insert.html.p"> | |
210 <xsl:with-param name="mark" select="$footnote.mark"/> | |
211 </xsl:apply-templates> | |
212 </xsl:when> | |
213 <xsl:otherwise> | |
214 <xsl:apply-templates select="$html-nodes" mode="insert.html.text"> | |
215 <xsl:with-param name="mark" select="$footnote.mark"/> | |
216 </xsl:apply-templates> | |
217 </xsl:otherwise> | |
218 </xsl:choose> | |
219 </xsl:when> | |
220 <xsl:otherwise> | |
221 <xsl:copy-of select="$html"/> | |
222 </xsl:otherwise> | |
223 </xsl:choose> | |
224 </xsl:template> | |
225 | |
226 <!-- ==================================================================== --> | |
227 | |
228 <!-- | |
229 <xsl:template name="count-element-from"> | |
230 <xsl:param name="from" select=".."/> | |
231 <xsl:param name="to" select="."/> | |
232 <xsl:param name="count" select="0"/> | |
233 <xsl:param name="list" select="$from/following::*[local-name(.)=local-name($to
)] | |
234 |$from/descendant-or-self::*[local-name(.)=loca
l-name($to)]"/> | |
235 | |
236 <xsl:choose> | |
237 <xsl:when test="not($list)"> | |
238 <xsl:text>-1</xsl:text> | |
239 </xsl:when> | |
240 <xsl:when test="$list[1] = $to"> | |
241 <xsl:value-of select="$count + 1"/> | |
242 </xsl:when> | |
243 <xsl:otherwise> | |
244 </xsl:otherwise> | |
245 </xsl:choose> | |
246 </xsl:template> | |
247 --> | |
248 | |
249 <!-- ==================================================================== --> | |
250 | |
251 <xsl:template name="process.footnotes"> | |
252 <xsl:variable name="footnotes" select=".//footnote"/> | |
253 <xsl:variable name="table.footnotes" | |
254 select=".//table//footnote | .//informaltable//footnote"/> | |
255 | |
256 <!-- Only bother to do this if there's at least one non-table footnote --> | |
257 <xsl:if test="count($footnotes)>count($table.footnotes)"> | |
258 <div class="footnotes"> | |
259 <xsl:call-template name="footnotes.attributes"/> | |
260 <br/> | |
261 <hr> | |
262 <xsl:choose> | |
263 <xsl:when test="$make.clean.html != 0"> | |
264 <xsl:attribute name="class">footnote-hr</xsl:attribute> | |
265 </xsl:when> | |
266 <xsl:when test="$css.decoration != 0"> | |
267 <xsl:attribute name="style"> | |
268 <xsl:value-of select="concat('width:100; text-align:', | |
269 $direction.align.start, | |
270 ';', | |
271 'margin-', $direction.align.start, '
: 0')"/> | |
272 </xsl:attribute> | |
273 </xsl:when> | |
274 <xsl:otherwise> | |
275 <xsl:attribute name="width">100</xsl:attribute> | |
276 <xsl:attribute name="align"><xsl:value-of | |
277 select="$direction.align.start"/></xsl:attribute> | |
278 </xsl:otherwise> | |
279 </xsl:choose> | |
280 </hr> | |
281 <xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/> | |
282 </div> | |
283 </xsl:if> | |
284 | |
285 <xsl:if test="$annotation.support != 0 and //annotation"> | |
286 <div class="annotation-list"> | |
287 <div class="annotation-nocss"> | |
288 <p>The following annotations are from this essay. You are seeing | |
289 them here because your browser doesn’t support the user-interface | |
290 techniques used to make them appear as ‘popups’ on modern browsers.</p> | |
291 </div> | |
292 | |
293 <xsl:apply-templates select="//annotation" | |
294 mode="annotation-popup"/> | |
295 </div> | |
296 </xsl:if> | |
297 </xsl:template> | |
298 | |
299 <xsl:template name="footnotes.attributes"> | |
300 <!-- customizable for footnotes attributes --> | |
301 </xsl:template> | |
302 | |
303 <xsl:template name="process.chunk.footnotes"> | |
304 <!-- nop --> | |
305 </xsl:template> | |
306 | |
307 <xsl:template match="footnote" name="process.footnote" mode="process.footnote.mo
de"> | |
308 <xsl:variable name="id"> | |
309 <xsl:text>ftn.</xsl:text> | |
310 <xsl:call-template name="object.id"> | |
311 <xsl:with-param name="conditional" select="0"/> | |
312 </xsl:call-template> | |
313 </xsl:variable> | |
314 | |
315 <xsl:choose> | |
316 <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'"> | |
317 <div id="{$id}"> | |
318 <xsl:call-template name="common.html.attributes"/> | |
319 <xsl:apply-templates/> | |
320 </div> | |
321 </xsl:when> | |
322 | |
323 <xsl:when test="$html.cleanup != 0 and | |
324 $exsl.node.set.available != 0"> | |
325 <div id="{$id}"> | |
326 <xsl:call-template name="common.html.attributes"/> | |
327 <xsl:call-template name="id.attribute"/> | |
328 <xsl:apply-templates select="*[1]" mode="footnote.body.number"/> | |
329 <xsl:apply-templates select="*[position() > 1]"/> | |
330 </div> | |
331 </xsl:when> | |
332 | |
333 <xsl:otherwise> | |
334 <xsl:message> | |
335 <xsl:text>Warning: footnote number may not be generated </xsl:text> | |
336 <xsl:text>correctly; </xsl:text> | |
337 <xsl:value-of select="local-name(*[1])"/> | |
338 <xsl:text> unexpected as first child of footnote.</xsl:text> | |
339 </xsl:message> | |
340 <div id="{$id}"> | |
341 <xsl:call-template name="common.html.attributes"/> | |
342 <xsl:call-template name="id.attribute"/> | |
343 <xsl:apply-templates/> | |
344 </div> | |
345 </xsl:otherwise> | |
346 </xsl:choose> | |
347 </xsl:template> | |
348 | |
349 <xsl:template match="table//footnote | informaltable//footnote" | |
350 mode="process.footnote.mode"> | |
351 </xsl:template> | |
352 | |
353 <xsl:template match="footnote" mode="table.footnote.mode"> | |
354 <xsl:call-template name="process.footnote"/> | |
355 </xsl:template> | |
356 | |
357 </xsl:stylesheet> | |
OLD | NEW |