Rocco Rutte:
[apps/madmutt.git] / doc / xslt / xhtml / footnote.xsl
1 <?xml version="1.0" encoding="US-ASCII"?>
2 <!--This file was created automatically by html2xhtml-->
3 <!--from the HTML stylesheets. Do not edit this file.-->
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$
8      ********************************************************************
9
10      This file is part of the XSL DocBook Stylesheet distribution.
11      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
12      and other information.
13
14      ******************************************************************** -->
15
16 <xsl:template match="footnote">
17   <xsl:variable name="name">
18     <xsl:call-template name="object.id"/>
19   </xsl:variable>
20   <xsl:variable name="href">
21     <xsl:text>#ftn.</xsl:text>
22     <xsl:call-template name="object.id"/>
23   </xsl:variable>
24
25   <xsl:choose>
26     <xsl:when test="ancestor::tgroup">
27       <sup>
28         <xsl:text>[</xsl:text>
29         <a id="{$name}" href="{$href}">
30           <xsl:apply-templates select="." mode="footnote.number"/>
31         </a>
32         <xsl:text>]</xsl:text>
33       </sup>
34     </xsl:when>
35     <xsl:otherwise>
36       <sup>
37         <xsl:text>[</xsl:text>
38         <a id="{$name}" href="{$href}">
39           <xsl:apply-templates select="." mode="footnote.number"/>
40         </a>
41         <xsl:text>]</xsl:text>
42       </sup>
43     </xsl:otherwise>
44   </xsl:choose>
45 </xsl:template>
46
47 <xsl:template match="footnoteref">
48   <xsl:variable name="targets" select="key('id',@linkend)"/>
49   <xsl:variable name="footnote" select="$targets[1]"/>
50   <xsl:variable name="href">
51     <xsl:text>#ftn.</xsl:text>
52     <xsl:call-template name="object.id">
53       <xsl:with-param name="object" select="$footnote"/>
54     </xsl:call-template>
55   </xsl:variable>
56   <sup>
57     <xsl:text>[</xsl:text>
58     <a href="{$href}">
59       <xsl:apply-templates select="$footnote" mode="footnote.number"/>
60     </a>
61     <xsl:text>]</xsl:text>
62   </sup>
63 </xsl:template>
64
65 <xsl:template match="footnote" mode="footnote.number">
66   <xsl:choose>
67     <xsl:when test="string-length(@label) != 0">
68       <xsl:value-of select="@label"/>
69     </xsl:when>
70     <xsl:when test="ancestor::tgroup">
71       <xsl:variable name="tfnum">
72         <xsl:number level="any" from="table|informaltable" format="1"/>
73       </xsl:variable>
74
75       <xsl:choose>
76         <xsl:when test="string-length($table.footnote.number.symbols) &gt;= $tfnum">
77           <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/>
78         </xsl:when>
79         <xsl:otherwise>
80           <xsl:number level="any" from="tgroup" format="{$table.footnote.number.format}"/>
81         </xsl:otherwise>
82       </xsl:choose>
83     </xsl:when>
84     <xsl:otherwise>
85       <xsl:variable name="pfoot" select="preceding::footnote[not(@label)]"/>
86       <xsl:variable name="ptfoot" select="preceding::tgroup//footnote"/>
87       <xsl:variable name="fnum" select="count($pfoot) - count($ptfoot) + 1"/>
88
89       <xsl:choose>
90         <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
91           <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
92         </xsl:when>
93         <xsl:otherwise>
94           <xsl:number value="$fnum" format="{$footnote.number.format}"/>
95         </xsl:otherwise>
96       </xsl:choose>
97     </xsl:otherwise>
98   </xsl:choose>
99 </xsl:template>
100
101 <!-- ==================================================================== -->
102
103 <xsl:template match="footnote/para[1]|footnote/simpara[1]" priority="2">
104   <!-- this only works if the first thing in a footnote is a para, -->
105   <!-- which is ok, because it usually is. -->
106   <xsl:variable name="name">
107     <xsl:text>ftn.</xsl:text>
108     <xsl:call-template name="object.id">
109       <xsl:with-param name="object" select="ancestor::footnote"/>
110     </xsl:call-template>
111   </xsl:variable>
112   <xsl:variable name="href">
113     <xsl:text>#</xsl:text>
114     <xsl:call-template name="object.id">
115       <xsl:with-param name="object" select="ancestor::footnote"/>
116     </xsl:call-template>
117   </xsl:variable>
118   <p>
119     <xsl:if test="@role and $para.propagates.style != 0">
120       <xsl:attribute name="class">
121         <xsl:value-of select="@role"/>
122       </xsl:attribute>
123     </xsl:if>
124     <sup>
125       <xsl:text>[</xsl:text>
126       <a id="{$name}" href="{$href}">
127         <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
128       </a>
129       <xsl:text>] </xsl:text>
130     </sup>
131     <xsl:apply-templates/>
132   </p>
133 </xsl:template>
134
135 <!-- ==================================================================== -->
136
137 <xsl:template match="*" mode="footnote.body.number">
138   <xsl:variable name="name">
139     <xsl:text>ftn.</xsl:text>
140     <xsl:call-template name="object.id">
141       <xsl:with-param name="object" select="ancestor::footnote"/>
142     </xsl:call-template>
143   </xsl:variable>
144   <xsl:variable name="href">
145     <xsl:text>#</xsl:text>
146     <xsl:call-template name="object.id">
147       <xsl:with-param name="object" select="ancestor::footnote"/>
148     </xsl:call-template>
149   </xsl:variable>
150   <xsl:variable name="footnote.mark">
151     <sup>
152       <xsl:text>[</xsl:text>
153       <a id="{$name}" href="{$href}">
154         <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
155       </a>
156       <xsl:text>] </xsl:text>
157     </sup>
158   </xsl:variable>
159
160   <xsl:variable name="html">
161     <xsl:apply-templates select="."/>
162   </xsl:variable>
163
164   <xsl:choose>
165     <xsl:when test="function-available('exsl:node-set')">
166       <xsl:variable name="html-nodes" select="exsl:node-set($html)"/>
167       <xsl:choose>
168         <xsl:when test="$html-nodes//p">
169           <xsl:apply-templates select="$html-nodes" mode="insert.html.p">
170             <xsl:with-param name="mark" select="$footnote.mark"/>
171           </xsl:apply-templates>
172         </xsl:when>
173         <xsl:otherwise>
174           <xsl:apply-templates select="$html-nodes" mode="insert.html.text">
175             <xsl:with-param name="mark" select="$footnote.mark"/>
176           </xsl:apply-templates>
177         </xsl:otherwise>
178       </xsl:choose>
179     </xsl:when>
180     <xsl:otherwise>
181       <xsl:copy-of select="$html"/>
182     </xsl:otherwise>
183   </xsl:choose>
184 </xsl:template>
185
186 <!-- ==================================================================== -->
187
188 <!--
189 <xsl:template name="count-element-from">
190   <xsl:param name="from" select=".."/>
191   <xsl:param name="to" select="."/>
192   <xsl:param name="count" select="0"/>
193   <xsl:param name="list" select="$from/following::*[name(.)=name($to)]
194                                  |$from/descendant-or-self::*[name(.)=name($to)]"/>
195
196   <xsl:choose>
197     <xsl:when test="not($list)">
198       <xsl:text>-1</xsl:text>
199     </xsl:when>
200     <xsl:when test="$list[1] = $to">
201       <xsl:value-of select="$count + 1"/>
202     </xsl:when>
203     <xsl:otherwise>
204     </xsl:otherwise>
205   </xsl:choose>
206 </xsl:template>
207 -->
208
209 <!-- ==================================================================== -->
210
211 <xsl:template name="process.footnotes">
212   <xsl:variable name="footnotes" select=".//footnote"/>
213   <xsl:variable name="table.footnotes" select=".//tgroup//footnote"/>
214
215   <!-- Only bother to do this if there's at least one non-table footnote -->
216   <xsl:if test="count($footnotes)&gt;count($table.footnotes)">
217     <div class="footnotes">
218       <br/>
219       <hr width="100" align="left"/>
220       <xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/>
221     </div>
222   </xsl:if>
223
224   <xsl:if test="$annotation.support != 0 and //annotation">
225     <div class="annotation-list">
226       <div class="annotation-nocss">
227         <p>The following annotations are from this essay. You are seeing
228         them here because your browser doesn&#8217;t support the user-interface
229         techniques used to make them appear as &#8216;popups&#8217; on modern browsers.</p>
230       </div>
231
232       <xsl:apply-templates select="//annotation" mode="annotation-popup"/>
233     </div>
234   </xsl:if>
235 </xsl:template>
236
237 <xsl:template name="process.chunk.footnotes">
238   <!-- nop -->
239 </xsl:template>
240
241 <xsl:template match="footnote" name="process.footnote" mode="process.footnote.mode">
242   <xsl:choose>
243     <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
244       <div class="{name(.)}">
245         <xsl:apply-templates/>
246       </div>
247     </xsl:when>
248
249     <xsl:when test="$html.cleanup != 0 and function-available('exsl:node-set')">
250       <div class="{name(.)}">
251         <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
252         <xsl:apply-templates select="*[position() &gt; 1]"/>
253       </div>
254     </xsl:when>
255
256     <xsl:otherwise>
257       <xsl:message>
258         <xsl:text>Warning: footnote number may not be generated </xsl:text>
259         <xsl:text>correctly; </xsl:text>
260         <xsl:value-of select="local-name(*[1])"/>
261         <xsl:text> unexpected as first child of footnote.</xsl:text>
262       </xsl:message>
263       <div class="{name(.)}">
264         <xsl:apply-templates/>
265       </div>
266     </xsl:otherwise>
267   </xsl:choose>
268 </xsl:template>
269
270 <xsl:template match="tgroup//footnote" mode="process.footnote.mode">
271 </xsl:template>
272
273 <xsl:template match="footnote" mode="table.footnote.mode">
274   <xsl:call-template name="process.footnote"/>
275 </xsl:template>
276
277 </xsl:stylesheet>