Debian Codegraph @

docbook-xsl-ns/fo/footnote.xsl

raw symbols SCIP
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:d="http://docbook.org/ns/docbook"
4 xmlns:fo="http://www.w3.org/1999/XSL/Format"
5 xmlns:xlink="http://www.w3.org/1999/xlink"
6 xmlns:exsl="http://exslt.org/common"
7 exclude-result-prefixes="exsl xlink d"
8 version='1.0'>
9
10 <!-- ********************************************************************
11
12 This file is part of the XSL DocBook Stylesheet distribution.
13 See ../README or http://cdn.docbook.org/release/xsl/current/ for
14 copyright and other information.
15
16 ******************************************************************** -->
17
18 <xsl:template name="format.footnote.mark">
19 <xsl:param name="mark" select="'?'"/>
20 <fo:inline xsl:use-attribute-sets="footnote.mark.properties">
21 <xsl:choose>
22 <xsl:when test="$fop.extensions != 0">
23 <xsl:attribute name="vertical-align">super</xsl:attribute>
24 </xsl:when>
25 <xsl:otherwise>
26 <xsl:attribute name="baseline-shift">super</xsl:attribute>
27 </xsl:otherwise>
28 </xsl:choose>
29 <xsl:copy-of select="$mark"/>
30 </fo:inline>
31 </xsl:template>
32
33 <xsl:template match="d:footnote">
34 <xsl:choose>
35 <xsl:when test="ancestor::d:table or ancestor::d:informaltable">
36 <xsl:call-template name="format.footnote.mark">
37 <xsl:with-param name="mark">
38 <xsl:apply-templates select="." mode="footnote.number"/>
39 </xsl:with-param>
40 </xsl:call-template>
41 </xsl:when>
42 <xsl:otherwise>
43 <fo:footnote>
44 <fo:inline>
45 <xsl:call-template name="format.footnote.mark">
46 <xsl:with-param name="mark">
47 <xsl:apply-templates select="." mode="footnote.number"/>
48 </xsl:with-param>
49 </xsl:call-template>
50 </fo:inline>
51 <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
52 <xsl:apply-templates/>
53 </fo:footnote-body>
54 </fo:footnote>
55 </xsl:otherwise>
56 </xsl:choose>
57 </xsl:template>
58
59 <xsl:template match="d:footnoteref">
60 <xsl:variable name="footnote" select="key('id',@linkend)"/>
61
62 <xsl:if test="not(local-name($footnote) = 'footnote')">
63 <xsl:message terminate="yes">
64 ERROR: A footnoteref element has a linkend that points to an element that is not a footnote.
65 Typically this happens when an id attribute is accidentally applied to the child of a footnote element.
66 target element: <xsl:value-of select="local-name($footnote)"/>
67 linkend/id: <xsl:value-of select="@linkend"/>
68 </xsl:message>
69 </xsl:if>
70
71 <xsl:call-template name="format.footnote.mark">
72 <xsl:with-param name="mark">
73 <xsl:apply-templates select="$footnote" mode="footnote.number"/>
74 </xsl:with-param>
75 </xsl:call-template>
76 </xsl:template>
77
78 <xsl:template match="d:footnote" mode="footnote.number">
79 <xsl:choose>
80 <xsl:when test="string-length(@label) != 0">
81 <xsl:value-of select="@label"/>
82 </xsl:when>
83 <xsl:when test="ancestor::d:table or ancestor::d:informaltable">
84 <xsl:variable name="tfnum">
85 <xsl:number level="any" from="d:table|d:informaltable" format="1"/>
86 </xsl:variable>
87
88 <xsl:choose>
89 <xsl:when test="string-length($table.footnote.number.symbols) &gt;= $tfnum">
90 <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/>
91 </xsl:when>
92 <xsl:otherwise>
93 <xsl:number level="any" from="d:table|d:informaltable"
94 format="{$table.footnote.number.format}"/>
95 </xsl:otherwise>
96 </xsl:choose>
97 </xsl:when>
98 <xsl:otherwise>
99 <xsl:variable name="fnum">
100 <!-- * Determine the footnote number to display for this footnote, -->
101 <!-- * by counting all foonotes, ulinks, and any elements that have -->
102 <!-- * an xlink:href attribute that meets the following criteria: -->
103 <!-- * -->
104 <!-- * - the content of the element is not a URI that is the same -->
105 <!-- * URI as the value of the href attribute -->
106 <!-- * - the href attribute is not an internal ID reference (does -->
107 <!-- * not start with a hash sign) -->
108 <!-- * - the href is not part of an olink reference (the element -->
109 <!-- * - does not have an xlink:role attribute that indicates it is -->
110 <!-- * an olink, and the hrf does not contain a hash sign) -->
111 <!-- * - the element either has no xlink:type attribute or has -->
112 <!-- * an xlink:type attribute whose value is 'simple' -->
113 <!-- * -->
114 <!-- * Note that hyperlinks are counted only if both the value of -->
115 <!-- * ulink.footnotes is non-zero and the value of ulink.show is -->
116 <!-- * non-zero -->
117 <!-- FIXME: list in @from is probably not complete -->
118 <xsl:number level="any"
119 from="d:chapter|d:appendix|d:preface|d:article|d:refentry|d:bibliography"
120 count="d:footnote[not(@label)][not(ancestor::d:table) and not(ancestor::d:informaltable)]
121 |d:ulink[$ulink.footnotes != 0][node()][@url != .][not(ancestor::d:footnote)][$ulink.show != 0]
122 |*[node()][@xlink:href][not(@xlink:href = .)][not(starts-with(@xlink:href,'#'))]
123 [not(contains(@xlink:href,'#') and @xlink:role = $xolink.role)]
124 [not(@xlink:type) or @xlink:type='simple']
125 [not(ancestor::d:footnote)][$ulink.footnotes != 0][$ulink.show != 0]
126 "
127 format="1"/>
128 </xsl:variable>
129 <xsl:choose>
130 <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
131 <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
132 </xsl:when>
133 <xsl:otherwise>
134 <xsl:number value="$fnum" format="{$footnote.number.format}"/>
135 </xsl:otherwise>
136 </xsl:choose>
137 </xsl:otherwise>
138 </xsl:choose>
139 </xsl:template>
140
141 <!-- ==================================================================== -->
142
143 <xsl:template match="*" mode="footnote.body.number">
144 <xsl:variable name="footnote.mark">
145 <xsl:call-template name="format.footnote.mark">
146 <xsl:with-param name="mark">
147 <xsl:apply-templates select="ancestor::d:footnote" mode="footnote.number"/>
148 </xsl:with-param>
149 </xsl:call-template>
150 </xsl:variable>
151
152 <xsl:variable name="fo">
153 <xsl:apply-templates select="."/>
154 </xsl:variable>
155
156 <xsl:variable name="fo-nodes" select="exsl:node-set($fo)"/>
157
158 <xsl:choose>
159 <xsl:when test="$fo-nodes//fo:block">
160 <xsl:apply-templates select="$fo-nodes" mode="insert.fo.fnum">
161 <xsl:with-param name="mark" select="$footnote.mark"/>
162 </xsl:apply-templates>
163 </xsl:when>
164 <xsl:otherwise>
165 <xsl:apply-templates select="$fo-nodes" mode="insert.fo.text">
166 <xsl:with-param name="mark" select="$footnote.mark"/>
167 </xsl:apply-templates>
168 </xsl:otherwise>
169 </xsl:choose>
170 </xsl:template>
171
172 <!-- ==================================================================== -->
173
174 <xsl:template match="d:footnote/d:para[1]
175 |d:footnote/d:simpara[1]
176 |d:footnote/d:formalpara[1]"
177 priority="2">
178 <!-- this only works if the first thing in a footnote is a para, -->
179 <!-- which is ok, because it usually is. -->
180 <fo:block>
181 <xsl:call-template name="format.footnote.mark">
182 <xsl:with-param name="mark">
183 <xsl:apply-templates select="ancestor::d:footnote" mode="footnote.number"/>
184 </xsl:with-param>
185 </xsl:call-template>
186 <xsl:apply-templates/>
187 </fo:block>
188 </xsl:template>
189
190 <xsl:template match="d:footnote" mode="table.footnote.mode">
191 <xsl:choose>
192 <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
193 <fo:block xsl:use-attribute-sets="table.footnote.properties">
194 <xsl:apply-templates/>
195 </fo:block>
196 </xsl:when>
197
198 <xsl:when test="$exsl.node.set.available != 0">
199 <fo:block xsl:use-attribute-sets="table.footnote.properties">
200 <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
201 <xsl:apply-templates select="*[position() &gt; 1]"/>
202 </fo:block>
203 </xsl:when>
204
205 <xsl:otherwise>
206 <xsl:message>
207 <xsl:text>Warning: footnote number may not be generated </xsl:text>
208 <xsl:text>correctly; </xsl:text>
209 <xsl:value-of select="local-name(*[1])"/>
210 <xsl:text> unexpected as first child of footnote.</xsl:text>
211 </xsl:message>
212 <fo:block xsl:use-attribute-sets="table.footnote.properties">
213 <xsl:apply-templates/>
214 </fo:block>
215 </xsl:otherwise>
216 </xsl:choose>
217 </xsl:template>
218
219 </xsl:stylesheet>