Debian Codegraph @

docbook-xsl-ns/xhtml/footnote.xsl

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