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