Debian Codegraph @

docs/xsl-generic/manpages/endnotes.xsl

raw
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'>
9
10 <!-- ********************************************************************
11 $Id: endnotes.xsl 7254 2007-08-18 23:59:53Z xmldoc $
12 ********************************************************************
13
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.
17
18 ******************************************************************** -->
19
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.) -->
83
84 <!-- ==================================================================== -->
85
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
111 )
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>
174
175 <!-- ==================================================================== -->
176
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)"/>
196
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>
211
212 <xsl:variable name="notesource.number">
213 <!-- * Get the number for this notesource -->
214 <!-- * -->
215 <!-- * If this is an imagedata, audiodata, or videodata element -->
216 <!-- * OR if it's a non-empty element AND its string value is not -->
217 <!-- * equal to the value of its url or xlink:href attribute (if -->
218 <!-- * it has one) AND user wants endnotes numbered, only then -->
219 <!-- * do we output a number for it -->
220 <xsl:if test="(self::imagedata or
221 self::audiodata or
222 self::videodata or
223 (node()
224 and not(. = @url)
225 and not(. = @xlink:href))
226 )
227 and $man.endnotes.are.numbered != 0">
228 <!-- * To select the number for this notesource, we -->
229 <!-- * check the index of all earmarks for the current refentry -->
230 <!-- * and find the number of the indexed earmark which matches -->
231 <!-- * this notesource's earmark. -->
232 <!-- * Note that multiple notesources may share the same -->
233 <!-- * numbered earmark; in that case, they get the same number. -->
234 <!-- * -->
235 <xsl:choose>
236 <xsl:when test="self::ulink or
237 self::*[@xlink:href] or
238 self::imagedata or
239 self::audiodata or
240 self::videodata">
241 <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@uri = $earmark]/@number"/>
242 </xsl:when>
243 <xsl:otherwise>
244 <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@id = $earmark]/@number"/>
245 </xsl:otherwise>
246 </xsl:choose>
247 </xsl:if>
248 </xsl:variable>
249
250 <xsl:variable name="notesource.contents">
251 <xsl:choose>
252 <!-- * check to see if the element is empty or not -->
253 <xsl:when test="node()">
254 <!-- * this is a non-empty node, so process its contents -->
255 <xsl:apply-templates/>
256 <xsl:if test="../footnote or ../annotation">
257 <!-- * if this element is a footnote or annotation, we need to -->
258 <!-- * do some further checking on it, so we can emit warnings -->
259 <!-- * about potential problems -->
260 <xsl:for-each select="node()">
261 <xsl:if test="local-name() != 'para' and local-name() !=''">
262 <!-- * for each node we find as a child of a footnote or -->
263 <!-- * annotation, if it's not a para or a text node, emit a -->
264 <!-- * warning... because in manpages output, we can't render -->
265 <!-- * block-level child content of an endnote properly unless -->
266 <!-- * it's wrapped in a para that has some "prefatory" text -->
267 <xsl:variable name="parent-name" select="local-name(..)"/>
268 <xsl:variable name="refname" select="ancestor::refentry/refnamediv[1]/refname[1]"/>
269 <xsl:variable name="endnote-number">
270 <xsl:call-template name="pad-string">
271 <!-- * endnote number may be 2 digits, so pad it with a space -->
272 <!-- * if we have only 1 digit -->
273 <xsl:with-param name="padVar" select="concat('#',$notesource.number)"/>
274 <xsl:with-param name="length" select="3"/>
275 </xsl:call-template>
276 </xsl:variable>
277 <xsl:call-template name="log.message">
278 <xsl:with-param name="level">Warn</xsl:with-param>
279 <xsl:with-param name="source" select="$refname"/>
280 <xsl:with-param name="context-desc">
281 <xsl:text>endnote </xsl:text>
282 <xsl:value-of select="$endnote-number"/>
283 </xsl:with-param>
284 <xsl:with-param name="message">
285 <xsl:text>Bad: </xsl:text>
286 <xsl:value-of select="$parent-name"/>
287 <!-- * figure out which occurance of this element type this -->
288 <!-- * instance is and output a number in square brackets so -->
289 <!-- * that end-user can know which element to fix -->
290 <xsl:text>[</xsl:text>
291 <xsl:value-of select="count(preceding::*[local-name() = $parent-name]) + 1"/>
292 <xsl:text>]</xsl:text>
293 <xsl:text> in source</xsl:text>
294 </xsl:with-param>
295 </xsl:call-template>
296 <xsl:call-template name="log.message">
297 <xsl:with-param name="level">Note</xsl:with-param>
298 <xsl:with-param name="source" select="$refname"/>
299 <xsl:with-param name="context-desc">
300 <xsl:text>endnote </xsl:text>
301 <xsl:value-of select="$endnote-number"/>
302 </xsl:with-param>
303 <xsl:with-param name="message">
304 <xsl:text>Has: </xsl:text>
305 <xsl:value-of select="$parent-name"/>
306 <xsl:text>/</xsl:text>
307 <xsl:value-of select="local-name(.)"/>
308 </xsl:with-param>
309 </xsl:call-template>
310 <xsl:call-template name="log.message">
311 <xsl:with-param name="level">Note</xsl:with-param>
312 <xsl:with-param name="source" select="$refname"/>
313 <xsl:with-param name="context-desc">
314 <xsl:text>endnote </xsl:text>
315 <xsl:value-of select="$endnote-number"/>
316 </xsl:with-param>
317 <xsl:with-param name="message">
318 <xsl:text>Fix: </xsl:text>
319 <xsl:value-of select="$parent-name"/>
320 <xsl:text>/</xsl:text>
321 <xsl:text>para/</xsl:text>
322 <xsl:value-of select="local-name(.)"/>
323 </xsl:with-param>
324 </xsl:call-template>
325 </xsl:if>
326 </xsl:for-each>
327 </xsl:if>
328 </xsl:when>
329 <xsl:otherwise>
330 <!-- * Otherwise this is an empty link or an empty imagedata, -->
331 <!-- * audiodata, or videodata element, so we just get the -->
332 <!-- * value of its url, xlink:href, or fileref attribute. -->
333 <xsl:if test="$man.hyphenate.urls = 0
334 and $man.break.after.slash = 0">
335 <!-- * Add hyphenation suppression in URL output only if -->
336 <!-- * break.after.slash is also non-zero -->
337 <xsl:call-template name="suppress.hyphenation"/>
338 <xsl:text>\%</xsl:text>
339 </xsl:if>
340 <xsl:value-of select="$earmark"/>
341 </xsl:otherwise>
342 </xsl:choose>
343 </xsl:variable>
344
345 <xsl:if test="self::ulink or self::*[@xlink:href]">
346 <!-- * This is a hyperlink, so we need to decide how to format -->
347 <!-- * the inline contents of the link (to underline or not). -->
348 <xsl:choose>
349 <!-- * if user wants links underlined, underline (ital) it -->
350 <xsl:when test="$man.links.are.underlined != 0">
351 <xsl:variable name="link.wrapper">
352 <xsl:value-of select="$notesource.contents"/>
353 </xsl:variable>
354 <xsl:call-template name="italic">
355 <xsl:with-param name="node" select="exsl:node-set($link.wrapper)"/>
356 <xsl:with-param name="context" select="."/>
357 </xsl:call-template>
358 </xsl:when>
359 <xsl:otherwise>
360 <!-- * user doesn't want links underlined, so just display content -->
361 <xsl:value-of select="$notesource.contents"/>
362 </xsl:otherwise>
363 </xsl:choose>
364 </xsl:if>
365
366 <xsl:if test="$notesource.number != ''">
367 <!-- * Format the number by placing it in square brackets. FIXME: -->
368 <!-- * This formatting should probably be made user-configurable, -->
369 <!-- * to allow something other than just square brackets; e.g., -->
370 <!-- * Angle brackets<10> or Braces{10} -->
371 <xsl:text>\&amp;[</xsl:text>
372 <xsl:value-of select="$notesource.number"/>
373 <xsl:text>]</xsl:text>
374 <!-- * Note that the reason for the \& before the opening bracket -->
375 <!-- * is to prevent any possible linebreak from being introduced -->
376 <!-- * between the opening bracket and the following text. -->
377 </xsl:if>
378 </xsl:template>
379
380 <!-- ==================================================================== -->
381
382 <xsl:template name="endnotes.list">
383 <!-- We have stored earmark indexes for all refentry instances in the -->
384 <!-- current document, with the ID for each index being the same ID as -->
385 <!-- its corresponding refentry; so we now need to get the ID for the -->
386 <!-- current refentry so we can grab its corresponding earmark index -->
387 <xsl:variable name="current.refentry.id">
388 <xsl:value-of select="generate-id(.)"/>
389 </xsl:variable>
390
391 <xsl:variable name="endnotes.rtf">
392 <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
393 <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
394 </xsl:variable>
395 <xsl:variable name="all.earmark.indexes.in.current.document"
396 select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
397 <xsl:copy-of
398 select="$all.earmark.indexes.in.current.document/earmark.index
399 [@idref = $current.refentry.id]/earmark"/>
400 </xsl:variable>
401
402 <xsl:variable name="endnotes" select="exsl:node-set($endnotes.rtf)"/>
403
404 <!-- * check to see if we have actually found any content to use as -->
405 <!-- * endnotes; if we have, we generate the endnotes list, if not, -->
406 <!-- * we do nothing -->
407 <xsl:if test="$endnotes/node()">
408 <xsl:call-template name="format.endnotes.list">
409 <xsl:with-param name="endnotes" select="$endnotes"/>
410 </xsl:call-template>
411 </xsl:if>
412
413 </xsl:template>
414
415 <!-- ==================================================================== -->
416
417 <xsl:template name="format.endnotes.list">
418 <xsl:param name="endnotes"/>
419 <xsl:call-template name="mark.subheading"/>
420
421 <!-- * ======= make the endnotes-list section heading ============= -->
422 <xsl:text>.SH "</xsl:text>
423 <xsl:call-template name="string.upper">
424 <xsl:with-param name="string">
425 <xsl:choose>
426 <!-- * if user has specified a heading, use that -->
427 <xsl:when test="$man.endnotes.list.heading != ''">
428 <xsl:value-of select="$man.endnotes.list.heading"/>
429 </xsl:when>
430 <xsl:otherwise>
431 <!-- * otherwise, get localized heading from gentext -->
432 <!-- * (in English, NOTES) -->
433 <xsl:call-template name="gentext">
434 <xsl:with-param name="key" select="'Notes'"/>
435 </xsl:call-template>
436 </xsl:otherwise>
437 </xsl:choose>
438 </xsl:with-param>
439 </xsl:call-template>
440 <xsl:text>"&#10;</xsl:text>
441
442 <!-- * ================ process each earmark ====================== -->
443 <xsl:for-each select="$endnotes/earmark">
444 <!-- * make paragraph with hanging indent, and starting with a -->
445 <!-- * number in the form " 1." (padded to $man.indent.width - 1) -->
446 <xsl:text>.IP</xsl:text>
447 <xsl:text> "</xsl:text>
448 <xsl:variable name="endnote.number">
449 <xsl:value-of select="@number"/>
450 <xsl:text>.</xsl:text>
451 </xsl:variable>
452 <xsl:call-template name="pad-string">
453 <xsl:with-param name="padVar" select="$endnote.number"/>
454 <!-- FIXME: the following assumes that $man.indent.width is in -->
455 <!-- en's; also, this should probably use $list.indent instead -->
456 <xsl:with-param name="length" select="$man.indent.width - 1"/>
457 </xsl:call-template>
458 <xsl:text>"</xsl:text>
459 <xsl:if test="not($list-indent = '')">
460 <xsl:text> </xsl:text>
461 <xsl:value-of select="$list-indent"/>
462 </xsl:if>
463 <xsl:text>&#10;</xsl:text>
464
465 <!-- * ========================================================= -->
466 <!-- * print the notesource/endnote contents -->
467 <!-- * ========================================================= -->
468 <xsl:choose>
469 <xsl:when test="*/node()">
470 <!-- * if the earmark has non-empty child content, then -->
471 <!-- * its corresponding notesource is either a link or -->
472 <!-- * an instance of annotative text, so we want to -->
473 <!-- * display that content -->
474 <xsl:choose>
475 <xsl:when test="*/node()[name(.)!='']">
476 <!-- * if node is not text only, then process it as-is -->
477 <xsl:apply-templates select="*/node()"/>
478 </xsl:when>
479 <xsl:otherwise>
480 <!-- * otherwise node is text-only, so normalize it -->
481 <xsl:value-of select="normalize-space(*/node())"/>
482 </xsl:otherwise>
483 </xsl:choose>
484 </xsl:when>
485 <xsl:otherwise>
486 <!-- * otherwise, this earmark has empty content, -->
487 <!-- * which means its corresponding notesources is an -->
488 <!-- * imagedata, audiodata, or videodata instance; in -->
489 <!-- * that case, we use the value of the notesoures's -->
490 <!-- * @fileref attribute (which is stored in the -->
491 <!-- * earmark uri attribute) as the "contents" for -->
492 <!-- * this endnote/notesource -->
493 <xsl:value-of select="@uri"/>
494 </xsl:otherwise>
495 </xsl:choose>
496 <xsl:text>&#10;</xsl:text>
497
498 <!-- * ========================================================= -->
499 <!-- * print the URL for links -->
500 <!-- * ========================================================= -->
501 <!-- * In addition to the notesource contents, if the -->
502 <!-- * notesource is a link, we display the URL for the link. -->
503 <!-- * But for notesources that are imagedata, audiodata, or -->
504 <!-- * videodata instances, we don't want to (re)display the -->
505 <!-- * URL for those here, because for those elements, the -->
506 <!-- * notesource contents are the URL (the value of the -->
507 <!-- * @fileref attribute), and we have already rendered them. -->
508 <!-- * -->
509 <!-- * We know an earmark is a link if it has non-empty child -->
510 <!-- * content and a uri attribute; so we check for that -->
511 <!-- * condition here. -->
512 <xsl:if test="*/node() and @uri">
513 <xsl:text>.RS</xsl:text>
514 <xsl:if test="not($list-indent = '')">
515 <xsl:text> </xsl:text>
516 <xsl:value-of select="$list-indent"/>
517 </xsl:if>
518 <xsl:text>&#10;</xsl:text>
519 <!-- * Add hyphenation suppression in URL output only if -->
520 <!-- * $break.after.slash is also non-zero -->
521 <xsl:if test="$man.hyphenate.urls = 0
522 and $man.break.after.slash = 0">
523 <xsl:call-template name="suppress.hyphenation"/>
524 <xsl:text>\%</xsl:text>
525 </xsl:if>
526 <xsl:value-of select="@uri"/>
527 <xsl:text>&#10;</xsl:text>
528 <xsl:text>.RE</xsl:text>
529 <xsl:text>&#10;</xsl:text>
530 </xsl:if>
531
532 </xsl:for-each>
533 </xsl:template>
534
535 </xsl:stylesheet>