ld --as-needed compilation fixes with external libs.
[fvwm.git] / doc / docbook-xsl / manpages / endnotes.xsl
blobf4ab016844ea3104a56eed09393cedbfb26f3d98
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 xmlns:ng="http://docbook.org/docbook-ng"
5 xmlns:db="http://docbook.org/ns/docbook"
6 xmlns:xlink="http://www.w3.org/1999/xlink"
7 exclude-result-prefixes="db ng exsl xlink"
8 version='1.0'>
10 <!-- ********************************************************************
11 $Id: endnotes.xsl,v 1.1 2007/03/10 05:15:34 scott Exp $
12 ********************************************************************
14 This file is part of the XSL DocBook Stylesheet distribution.
15 See ../README or http://docbook.sf.net/release/xsl/current/ for
16 copyright and other information.
18 ******************************************************************** -->
20 <!-- ==================================================================== -->
21 <!-- * -->
22 <!-- * The templates in this file handle elements whose contents can't -->
23 <!-- * be displayed completely within the main text flow in output, but -->
24 <!-- * instead need to be displayed "out of line". Those elements are: -->
25 <!-- * -->
26 <!-- * - elements providing annotative text (annotation|alt|footnote) -->
27 <!-- * - elements pointing at external resources (ulink, link, and -->
28 <!-- * any elements with xlink:href attributes; and imagedata, -->
29 <!-- * audiodata, and videodata - which (using their fileref -->
30 <!-- * attribute) reference external files -->
31 <!-- * -->
32 <!-- * Within this stylesheet, the above are collectively referred to as -->
33 <!-- * a "notesources". This stylesheet handles those notesources in -->
34 <!-- * this way: -->
35 <!-- * -->
36 <!-- * 1. Constructs a numbered in-memory index of all unique "earmarks“ -->
37 <!-- * of all notesources in the document. For each link, the -->
38 <!-- * earmark is the value of its url or xlink:href attribute; for -->
39 <!-- * each imagedata|audiodata|videodata: the value of its fileref -->
40 <!-- * attribute; for each annotative element: its content. -->
41 <!-- * -->
42 <!-- * Notesources with the same earmark are assigned the same -->
43 <!-- * number. -->
44 <!-- * -->
45 <!-- * By design, that index excludes any element whose whose string -->
46 <!-- * value is identical to value of its url xlink:href attribute). -->
47 <!-- * -->
48 <!-- * 2. Puts a numbered marker inline to mark the place where the -->
49 <!-- * notesource occurs in the main text flow. -->
50 <!-- * -->
51 <!-- * 3. Generates a numbered endnotes list (titled NOTES in English) -->
52 <!-- * at the end of the man page, with the contents of each -->
53 <!-- * notesource. -->
54 <!-- * -->
55 <!-- * Note that table footnotes are not listed in the endnotes list, -->
56 <!-- * and are not handled by this stylesheet (they are instead handled -->
57 <!-- * by the table.xsl stylesheet). -->
58 <!-- * -->
59 <!-- * Also, we don't get notesources in *info sections or Refmeta or -->
60 <!-- * Refnamediv or Indexterm, because, in manpages output, contents of -->
61 <!-- * those are either suppressed or are displayed out of document -->
62 <!-- * order - for example, the Info/Author content gets moved to the -->
63 <!-- * end of the page. So, if we were to number notesources in the -->
64 <!-- * Author content, it would "throw off" the numbering at the -->
65 <!-- * beginning of the main text flow. -->
66 <!-- * -->
67 <!-- * And for the record, one reason we don't use xsl:key to index the -->
68 <!-- * earmarks is that we need to get and check the sets of -->
69 <!-- * earmarks for uniqueness per-Refentry (not per-document). -->
70 <!-- * -->
71 <!-- * FIXME: as -->
72 <!-- * with "repeat" URLS, alt instances that have the same string value -->
73 <!-- * as preceding ones (likely to occur for repeat acroynyms and -->
74 <!-- * abbreviations) should be listed only once in the endnotes list, -->
75 <!-- * and numbered accordingly inline; split man.indent.width into -->
76 <!-- * man.indent.width.value (default 4) and man.indent.width.units -->
77 <!-- * (default n); also, if the first child of notesource is some block -->
78 <!-- * content other than a (non-formal) paragraph, the current code -->
79 <!-- * will probably end up generating a blank line after the -->
80 <!-- * corresponding number in the endnotes list... we should probably -->
81 <!-- * try to instead display the title of that block content there (if -->
82 <!-- * there is one: e.g., the list title, admonition title, etc.) -->
84 <!-- ==================================================================== -->
86 <xsl:template name="get.all.earmark.indexes.in.current.document">
87 <!-- * Here we create a tree to hold indexes of all earmarks in -->
88 <!-- * the current document. If the current document contains -->
89 <!-- * multiple refentry instances, then this tree will contain -->
90 <!-- * multiple indexes. -->
91 <xsl:if test="$man.endnotes.are.numbered != 0">
92 <!-- * Only create earmark indexes if user wants numbered endnotes -->
93 <xsl:for-each select="//refentry">
94 <earmark.index>
95 <xsl:attribute name="idref">
96 <xsl:value-of select="generate-id()"/>
97 </xsl:attribute>
98 <xsl:for-each
99 select=".//*[self::*[@xlink:href]
100 or self::ulink
101 or self::imagedata
102 or self::audiodata
103 or self::videodata
104 or self::footnote[not(ancestor::table)]
105 or self::annotation
106 or self::alt]
107 [(node()
108 or self::imagedata
109 or self::audiodata
110 or self::videodata
112 and not(ancestor::refentryinfo)
113 and not(ancestor::info)
114 and not(ancestor::docinfo)
115 and not(ancestor::refmeta)
116 and not(ancestor::refnamediv)
117 and not(ancestor::indexterm)
118 and not(. = @url)
119 and not(. = @xlink:href)
120 and not(@url =
121 preceding::ulink[node()
122 and not(ancestor::refentryinfo)
123 and not(ancestor::info)
124 and not(ancestor::docinfo)
125 and not(ancestor::refmeta)
126 and not(ancestor::refnamediv)
127 and not(ancestor::indexterm)
128 and (generate-id(ancestor::refentry)
129 = generate-id(current()))]/@url)
130 and not(@xlink:href =
131 preceding::*[@xlink:href][node()
132 and not(ancestor::refentryinfo)
133 and not(ancestor::info)
134 and not(ancestor::docinfo)
135 and not(ancestor::refmeta)
136 and not(ancestor::refnamediv)
137 and not(ancestor::indexterm)
138 and (generate-id(ancestor::refentry)
139 = generate-id(current()))]/@xlink:href)
140 and not(@fileref =
141 preceding::*[@fileref][
142 not(ancestor::refentryinfo)
143 and not(ancestor::info)
144 and not(ancestor::docinfo)
145 and not(ancestor::refmeta)
146 and not(ancestor::refnamediv)
147 and not(ancestor::indexterm)
148 and (generate-id(ancestor::refentry)
149 = generate-id(current()))]/@fileref)]">
150 <earmark>
151 <xsl:attribute name="id">
152 <xsl:value-of select="generate-id()"/>
153 </xsl:attribute>
154 <xsl:attribute name="number">
155 <xsl:value-of select="position()"/>
156 </xsl:attribute>
157 <xsl:if test="@url|@xlink:href|@fileref">
158 <!-- * Only add a uri attribute if the notesource is -->
159 <!-- * a link or an element that references an external -->
160 <!-- * (an imagedata, audiodata, or videodata element) -->
161 <xsl:attribute name="uri">
162 <xsl:value-of select="@url|@xlink:href|@fileref"/>
163 </xsl:attribute>
164 </xsl:if>
165 <xsl:copy>
166 <xsl:copy-of select="node()"/>
167 </xsl:copy>
168 </earmark>
169 </xsl:for-each>
170 </earmark.index>
171 </xsl:for-each>
172 </xsl:if>
173 </xsl:template>
175 <!-- ==================================================================== -->
177 <xsl:template match="*[@xlink:href]|ulink
178 |imagedata|audiodata|videodata
179 |footnote[not(ancestor::table)]
180 |annotation|alt">
181 <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
182 <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
183 </xsl:variable>
184 <xsl:variable name="all.earmark.indexes.in.current.document"
185 select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
186 <xsl:variable name="all.earmarks.in.current.refentry.rtf">
187 <!-- * get the set of all earmarks for the ancestor Refentry of -->
188 <!-- * this notesource -->
189 <xsl:copy-of
190 select="$all.earmark.indexes.in.current.document/earmark.index
191 [@idref =
192 generate-id(current()/ancestor::refentry)]/earmark"/>
193 </xsl:variable>
194 <xsl:variable name="all.earmarks.in.current.refentry"
195 select="exsl:node-set($all.earmarks.in.current.refentry.rtf)"/>
197 <!-- * identify the earmark for the current element -->
198 <xsl:variable name="earmark">
199 <xsl:choose>
200 <xsl:when test="@url|@xlink:href">
201 <xsl:value-of select="@url|@xlink:href"/>
202 </xsl:when>
203 <xsl:when test="@fileref">
204 <xsl:value-of select="@fileref"/>
205 </xsl:when>
206 <xsl:otherwise>
207 <xsl:value-of select="generate-id()"/>
208 </xsl:otherwise>
209 </xsl:choose>
210 </xsl:variable>
212 <xsl:variable name="notesource.contents">
213 <xsl:choose>
214 <!-- * check to see if the element is empty or not; if it's -->
215 <!-- * non-empty, get the content -->
216 <xsl:when test="node()">
217 <xsl:apply-templates/>
218 </xsl:when>
219 <xsl:otherwise>
220 <!-- * Otherwise this is an empty link or an empty imagedata, -->
221 <!-- * audiodata, or videodata element, so we just get the -->
222 <!-- * value of its url, xlink:href, or fileref attribute. -->
223 <!-- * -->
224 <!-- * Add hyphenation suppression in URL output only if -->
225 <!-- * break.after.slash is also non-zero -->
226 <xsl:if test="$man.hyphenate.urls = 0 and
227 $man.break.after.slash = 0">
228 <xsl:call-template name="suppress.hyphenation"/>
229 <xsl:text>\%</xsl:text>
230 </xsl:if>
231 <xsl:value-of select="$earmark"/>
232 </xsl:otherwise>
233 </xsl:choose>
234 </xsl:variable>
236 <xsl:if test="self::ulink or self::*[@xlink:href]">
237 <!-- * This is a hyperlink, so we need to decide how to format -->
238 <!-- * the inline contents of the link (to underline or not). -->
239 <xsl:choose>
240 <!-- * if user wants links underlined, underline (ital) it -->
241 <xsl:when test="$man.links.are.underlined != 0">
242 <xsl:variable name="link.wrapper">
243 <italic><xsl:value-of select="$notesource.contents"/></italic>
244 </xsl:variable>
245 <xsl:apply-templates mode="italic"
246 select="exsl:node-set($link.wrapper)"/>
247 </xsl:when>
248 <xsl:otherwise>
249 <!-- * user doesn't want links underlined, so just display content -->
250 <xsl:value-of select="$notesource.contents"/>
251 </xsl:otherwise>
252 </xsl:choose>
253 </xsl:if>
255 <!-- * Format the numbered marker for this notesource -->
256 <!-- * -->
257 <!-- * If this is an imagedata, audiodata, or videodata element -->
258 <!-- * OR if it's a non-empty element AND its string value is not -->
259 <!-- * equal to the value of its url or xlink:href attribute (if -->
260 <!-- * it has one) AND user wants endnotes numbered, only then -->
261 <!-- * do we output a number for it -->
262 <xsl:if test="(self::imagedata or
263 self::audiodata or
264 self::videodata or
265 (node()
266 and not(. = @url)
267 and not(. = @xlink:href))
269 and $man.endnotes.are.numbered != 0">
270 <!-- * To generate the numbered marker for this notesource, we -->
271 <!-- * check the index of all earmarks for the current refentry -->
272 <!-- * and find the number of the indexed earmark which matches -->
273 <!-- * this notesource's earmark. -->
274 <!-- * Note that multiple notesources may share the same -->
275 <!-- * numbered earmark; in that case, they get the same number. -->
276 <!-- * -->
277 <xsl:variable name="notesource.number">
278 <xsl:choose>
279 <xsl:when test="self::ulink or
280 self::*[@xlink:href] or
281 self::imagedata or
282 self::audiodata or
283 self::videodata">
284 <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@uri = $earmark]/@number"/>
285 </xsl:when>
286 <xsl:otherwise>
287 <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@id = $earmark]/@number"/>
288 </xsl:otherwise>
289 </xsl:choose>
290 </xsl:variable>
292 <!-- * Format the number by placing it in square brackets. FIXME: -->
293 <!-- * This formatting should probably be made user-configurable, -->
294 <!-- * to allow something other than just square brackets; e.g., -->
295 <!-- * Angle brackets<10> or Braces{10} -->
296 <xsl:text>\&amp;[</xsl:text>
297 <xsl:value-of select="$notesource.number"/>
298 <xsl:text>]</xsl:text>
299 <!-- * Note that the reason for the \& before the opening bracket -->
300 <!-- * is to prevent any possible linebreak from being introduced -->
301 <!-- * between the opening bracket and the following text. -->
302 </xsl:if>
303 </xsl:template>
305 <!-- ==================================================================== -->
307 <xsl:template name="endnotes.list">
308 <!-- We have stored earmark indexes for all refentry instances in the -->
309 <!-- current document, with the ID for each index being the same ID as -->
310 <!-- its corresponding refentry; so we now need to get the ID for the -->
311 <!-- current refentry so we can grab its corresponding earmark index -->
312 <xsl:variable name="current.refentry.id">
313 <xsl:value-of select="generate-id(.)"/>
314 </xsl:variable>
316 <xsl:variable name="endnotes.rtf">
317 <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
318 <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
319 </xsl:variable>
320 <xsl:variable name="all.earmark.indexes.in.current.document"
321 select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
322 <xsl:copy-of
323 select="$all.earmark.indexes.in.current.document/earmark.index
324 [@idref = $current.refentry.id]/earmark"/>
325 </xsl:variable>
327 <xsl:variable name="endnotes" select="exsl:node-set($endnotes.rtf)"/>
329 <!-- * check to see if we have actually found any content to use as -->
330 <!-- * endnotes; if we have, we generate the endnotes list, if not, -->
331 <!-- * we do nothing -->
332 <xsl:if test="$endnotes/node()">
333 <xsl:call-template name="format.endnotes.list">
334 <xsl:with-param name="endnotes" select="$endnotes"/>
335 </xsl:call-template>
336 </xsl:if>
338 </xsl:template>
340 <!-- ==================================================================== -->
342 <xsl:template name="format.endnotes.list">
343 <xsl:param name="endnotes"/>
344 <xsl:call-template name="mark.subheading"/>
346 <!-- * ======= make the endnotes-list section heading ============= -->
347 <xsl:text>.SH "</xsl:text>
348 <xsl:call-template name="string.upper">
349 <xsl:with-param name="string">
350 <xsl:choose>
351 <!-- * if user has specified a heading, use that -->
352 <xsl:when test="$man.endnotes.list.heading != ''">
353 <xsl:value-of select="$man.endnotes.list.heading"/>
354 </xsl:when>
355 <xsl:otherwise>
356 <!-- * otherwise, get localized heading from gentext -->
357 <!-- * (in English, NOTES) -->
358 <xsl:call-template name="gentext">
359 <xsl:with-param name="key" select="'Notes'"/>
360 </xsl:call-template>
361 </xsl:otherwise>
362 </xsl:choose>
363 </xsl:with-param>
364 </xsl:call-template>
365 <xsl:text>"&#10;</xsl:text>
367 <!-- * ================ process each earmark ====================== -->
368 <xsl:for-each select="$endnotes/earmark">
369 <!-- * make paragraph with hanging indent, and starting with a -->
370 <!-- * number in the form " 1." (padded to $man.indent.width - 1) -->
371 <xsl:text>.IP</xsl:text>
372 <xsl:text> "</xsl:text>
373 <xsl:variable name="endnote.number">
374 <xsl:value-of select="@number"/>
375 <xsl:text>.</xsl:text>
376 </xsl:variable>
377 <xsl:call-template name="prepend-pad">
378 <xsl:with-param name="padVar" select="$endnote.number"/>
379 <!-- FIXME: the following assumes that $man.indent.width is in -->
380 <!-- en's; also, this should probably use $list.indent instead -->
381 <xsl:with-param name="length" select="$man.indent.width - 1"/>
382 </xsl:call-template>
383 <xsl:text>"</xsl:text>
384 <xsl:if test="not($list-indent = '')">
385 <xsl:text> </xsl:text>
386 <xsl:value-of select="$list-indent"/>
387 </xsl:if>
388 <xsl:text>&#10;</xsl:text>
390 <!-- * ========================================================= -->
391 <!-- * print the notesource/endnote contents -->
392 <!-- * ========================================================= -->
393 <xsl:choose>
394 <xsl:when test="*/node()">
395 <!-- * if the earmark has non-empty child content, then -->
396 <!-- * its corresponding notesource is either a link or -->
397 <!-- * an instance of annotative text, so we want to -->
398 <!-- * display that content -->
399 <xsl:apply-templates select="*/node()"/>
400 </xsl:when>
401 <xsl:otherwise>
402 <!-- * otherwise, this earmark has empty content, -->
403 <!-- * which means its corresponding notesources is an -->
404 <!-- * imagedata, audiodata, or videodata instance; in -->
405 <!-- * that case, we use the value of the notesoures's -->
406 <!-- * @fileref attribute (which is stored in the -->
407 <!-- * earmark uri attribute) as the "contents" for -->
408 <!-- * this endnote/notesource -->
409 <xsl:value-of select="@uri"/>
410 </xsl:otherwise>
411 </xsl:choose>
412 <xsl:text>&#10;</xsl:text>
414 <!-- * ========================================================= -->
415 <!-- * print the URL for links -->
416 <!-- * ========================================================= -->
417 <!-- * In addition to the notesource contents, if the -->
418 <!-- * notesource is a link, we display the URL for the link. -->
419 <!-- * But for notesources that are imagedata, audiodata, or -->
420 <!-- * videodata instances, we don't want to (re)display the -->
421 <!-- * URL for those here, because for those elements, the -->
422 <!-- * notesource contents are the URL (the value of the -->
423 <!-- * @fileref attribute), and we have already rendered them. -->
424 <!-- * -->
425 <!-- * We know an earmark is a link if it has non-empty child -->
426 <!-- * content and a uri attribute; so we check for that -->
427 <!-- * condition here. -->
428 <xsl:if test="*/node() and @uri">
429 <xsl:text>.RS</xsl:text>
430 <xsl:if test="not($list-indent = '')">
431 <xsl:text> </xsl:text>
432 <xsl:value-of select="$list-indent"/>
433 </xsl:if>
434 <xsl:text>&#10;</xsl:text>
435 <!-- * Add hyphenation suppression in URL output only if -->
436 <!-- * $break.after.slash is also non-zero -->
437 <xsl:if test="$man.hyphenate.urls = 0
438 and $man.break.after.slash = 0">
439 <xsl:call-template name="suppress.hyphenation"/>
440 <xsl:text>\%</xsl:text>
441 </xsl:if>
442 <xsl:value-of select="@uri"/>
443 <xsl:text>&#10;</xsl:text>
444 <xsl:text>.RE</xsl:text>
445 <xsl:text>&#10;</xsl:text>
446 </xsl:if>
448 </xsl:for-each>
449 </xsl:template>
451 </xsl:stylesheet>