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"
10 <!-- ********************************************************************
11 $Id: endnotes.xsl 8490 2009-07-18 17:48:06Z mzjn $
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 <!-- ==================================================================== -->
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: -->
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 -->
32 <!-- * Within this stylesheet, the above are collectively referred to as -->
33 <!-- * a "notesources". This stylesheet handles those notesources in -->
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. -->
42 <!-- * Notesources with the same earmark are assigned the same -->
45 <!-- * By design, that index excludes any element whose string value -->
46 <!-- * is identical to the value of its url xlink:href attribute). -->
48 <!-- * 2. Puts a numbered marker inline to mark the place where the -->
49 <!-- * notesource occurs in the main text flow. -->
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. -->
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). -->
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. -->
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). -->
72 <!-- * as 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">
95 <xsl:attribute name="idref">
96 <xsl:value-of select="generate-id()"/>
99 select=".//*[self::*[@xlink:href]
104 or self::footnote[not(ancestor::table)]
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)
119 and not(. = @xlink:href)
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)
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)]">
151 <xsl:attribute name="id">
152 <xsl:value-of select="generate-id()"/>
154 <xsl:attribute name="number">
155 <xsl:value-of select="position()"/>
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"/>
166 <xsl:copy-of select="node()"/>
175 <!-- ==================================================================== -->
177 <xsl:template match="*[@xlink:href]|ulink
178 |imagedata|audiodata|videodata
179 |footnote[not(ancestor::table)]
181 <xsl:variable name="refname" select="ancestor::refentry/refnamediv[1]/refname[1]"/>
182 <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
183 <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
185 <xsl:variable name="all.earmark.indexes.in.current.document"
186 select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
187 <xsl:variable name="all.earmarks.in.current.refentry.rtf">
188 <!-- * get the set of all earmarks for the ancestor Refentry of -->
189 <!-- * this notesource -->
191 select="$all.earmark.indexes.in.current.document/earmark.index
193 generate-id(current()/ancestor::refentry)]/earmark"/>
195 <xsl:variable name="all.earmarks.in.current.refentry"
196 select="exsl:node-set($all.earmarks.in.current.refentry.rtf)"/>
198 <!-- * identify the earmark for the current element -->
199 <xsl:variable name="earmark">
201 <xsl:when test="@url|@xlink:href">
202 <xsl:value-of select="@url|@xlink:href"/>
204 <xsl:when test="@fileref">
205 <xsl:value-of select="@fileref"/>
208 <xsl:value-of select="generate-id()"/>
213 <xsl:variable name="notesource.number">
214 <!-- * Get the number for this notesource -->
216 <!-- * If this is an imagedata, audiodata, or videodata element -->
217 <!-- * OR if it's a non-empty element AND its string value is not -->
218 <!-- * equal to the value of its url or xlink:href attribute (if -->
219 <!-- * it has one) AND user wants endnotes numbered, only then -->
220 <!-- * do we output a number for it -->
221 <xsl:if test="(self::imagedata or
226 and not(. = @xlink:href))
228 and $man.endnotes.are.numbered != 0">
229 <!-- * To select the number for this notesource, we -->
230 <!-- * check the index of all earmarks for the current refentry -->
231 <!-- * and find the number of the indexed earmark which matches -->
232 <!-- * this notesource's earmark. -->
233 <!-- * Note that multiple notesources may share the same -->
234 <!-- * numbered earmark; in that case, they get the same number. -->
237 <xsl:when test="self::ulink or
238 self::*[@xlink:href] or
242 <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@uri = $earmark]/@number"/>
245 <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@id = $earmark]/@number"/>
251 <xsl:variable name="notesource.contents">
253 <!-- * check to see if the element is empty or not -->
254 <xsl:when test="node()">
255 <!-- * this is a non-empty node, so process its contents -->
256 <xsl:apply-templates/>
257 <xsl:if test="../footnote or ../annotation">
258 <!-- * if this element is a footnote or annotation, we need to -->
259 <!-- * do some further checking on it, so we can emit warnings -->
260 <!-- * about potential problems -->
261 <xsl:for-each select="node()">
262 <xsl:if test="local-name() != 'para' and local-name() !=''">
263 <!-- * for each node we find as a child of a footnote or -->
264 <!-- * annotation, if it's not a para or a text node, emit a -->
265 <!-- * warning... because in manpages output, we can't render -->
266 <!-- * block-level child content of an endnote properly unless -->
267 <!-- * it's wrapped in a para that has some "prefatory" text -->
268 <xsl:variable name="parent-name" select="local-name(..)"/>
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"/>
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"/>
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>
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"/>
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(.)"/>
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"/>
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(.)"/>
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>
340 <xsl:value-of select="$earmark"/>
345 <xsl:if test="self::ulink or self::*[@xlink:href]">
346 <xsl:variable name="link.wrapper">
347 <xsl:value-of select="normalize-space($notesource.contents)"/>
349 <xsl:text>\m[blue]</xsl:text>
350 <!-- * This is a hyperlink, so we need to determine if the user wants -->
351 <!-- * font formatting applied to it, and if so, what font -->
353 <xsl:when test="$man.font.links = 'B'">
354 <xsl:call-template name="bold">
355 <xsl:with-param name="node" select="exsl:node-set($link.wrapper)"/>
356 <xsl:with-param name="context" select="."/>
359 <xsl:when test="$man.font.links = 'I'">
360 <xsl:call-template name="italic">
361 <xsl:with-param name="node" select="exsl:node-set($link.wrapper)"/>
362 <xsl:with-param name="context" select="."/>
365 <xsl:when test="$man.font.links = ''">
366 <!-- * if man.font.links is empty, user doesn't want links -->
367 <!-- * underlined, so just display content -->
368 <xsl:value-of select="$notesource.contents"/>
371 <!-- * otherwise the user has specified an unsupported value for -->
372 <!-- * man.font.links, so emit a warning and don't apply any font -->
373 <!-- * formatting -->
375 <xsl:call-template name="log.message">
376 <xsl:with-param name="level">Warn</xsl:with-param>
377 <xsl:with-param name="source" select="$refname"/>
378 <xsl:with-param name="context-desc">
379 <xsl:text>link font</xsl:text>
381 <xsl:with-param name="message">
382 <xsl:text>invalid $man.font.links value: </xsl:text>
383 <xsl:text>'</xsl:text>
384 <xsl:value-of select="$man.font.links"/>
385 <xsl:text>'</xsl:text>
389 <xsl:value-of select="$notesource.contents"/>
392 <xsl:text>\m[]</xsl:text>
395 <xsl:if test="$notesource.number != ''">
396 <!-- * Format the number by placing it in square brackets. -->
397 <!-- * Also, set the number in font-size -2, and superscripted (\u -->
398 <!-- * means to move up half a line vertically) -->
399 <xsl:text>\&\s-2\u[</xsl:text>
400 <xsl:value-of select="$notesource.number"/>
401 <xsl:text>]\d\s+2</xsl:text>
402 <!-- * Revert superscripting (\d means to move down half a line), and -->
403 <!-- * move the font-size back to what it was before. -->
404 <!-- * Note that the reason for the \& before the opening bracket -->
405 <!-- * is to prevent any possible linebreak from being introduced -->
406 <!-- * between the opening bracket and the following text. -->
410 <!-- ==================================================================== -->
412 <xsl:template name="endnotes.list">
413 <!-- We have stored earmark indexes for all refentry instances in the -->
414 <!-- current document, with the ID for each index being the same ID as -->
415 <!-- its corresponding refentry; so we now need to get the ID for the -->
416 <!-- current refentry so we can grab its corresponding earmark index -->
417 <xsl:variable name="current.refentry.id">
418 <xsl:value-of select="generate-id(.)"/>
421 <xsl:variable name="endnotes.rtf">
422 <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
423 <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
425 <xsl:variable name="all.earmark.indexes.in.current.document"
426 select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
428 select="$all.earmark.indexes.in.current.document/earmark.index
429 [@idref = $current.refentry.id]/earmark"/>
432 <xsl:variable name="endnotes" select="exsl:node-set($endnotes.rtf)"/>
434 <!-- * check to see if we have actually found any content to use as -->
435 <!-- * endnotes; if we have, we generate the endnotes list, if not, -->
436 <!-- * we do nothing -->
437 <xsl:if test="$endnotes/node()">
438 <xsl:call-template name="format.endnotes.list">
439 <xsl:with-param name="endnotes" select="$endnotes"/>
445 <!-- ==================================================================== -->
447 <xsl:template name="format.endnotes.list">
448 <xsl:param name="endnotes"/>
450 <!-- * ======= make the endnotes-list section heading ============= -->
451 <xsl:call-template name="make.subheading">
452 <xsl:with-param name="title">
454 <!-- * if user has specified a heading, use that -->
455 <xsl:when test="$man.endnotes.list.heading != ''">
456 <xsl:value-of select="$man.endnotes.list.heading"/>
459 <!-- * otherwise, get localized heading from gentext -->
460 <!-- * (in English, NOTES) -->
461 <xsl:call-template name="gentext">
462 <xsl:with-param name="key" select="'Notes'"/>
469 <!-- * ================ process each earmark ====================== -->
470 <xsl:for-each select="$endnotes/earmark">
471 <!-- * make paragraph with hanging indent, and starting with a -->
472 <!-- * number in the form " 1." (padded to $man.indent.width - 1) -->
473 <xsl:text>.IP</xsl:text>
474 <xsl:text> "</xsl:text>
475 <xsl:variable name="endnote.number">
476 <xsl:value-of select="@number"/>
477 <xsl:text>.</xsl:text>
479 <xsl:call-template name="pad-string">
480 <xsl:with-param name="padVar" select="$endnote.number"/>
481 <!-- FIXME: the following assumes that $man.indent.width is in -->
482 <!-- en's; also, this should probably use $list.indent instead -->
483 <xsl:with-param name="length" select="$man.indent.width - 1"/>
485 <xsl:text>"</xsl:text>
486 <xsl:if test="not($list-indent = '')">
487 <xsl:text> </xsl:text>
488 <xsl:value-of select="$list-indent"/>
490 <xsl:text> </xsl:text>
492 <!-- * ========================================================= -->
493 <!-- * print the notesource/endnote contents -->
494 <!-- * ========================================================= -->
496 <xsl:when test="*/node()">
497 <!-- * if the earmark has non-empty child content, then -->
498 <!-- * its corresponding notesource is either a link or -->
499 <!-- * an instance of annotative text, so we want to -->
500 <!-- * display that content -->
502 <xsl:when test="*/node()[name(.)!='']">
503 <!-- * if node is not text only, then process it as-is -->
504 <xsl:apply-templates select="*/node()"/>
507 <!-- * otherwise node is text-only, so normalize it -->
508 <xsl:value-of select="normalize-space(*/node())"/>
513 <!-- * otherwise, this earmark has empty content, -->
514 <!-- * which means its corresponding notesource is an -->
515 <!-- * imagedata, audiodata, or videodata instance; in -->
516 <!-- * that case, we use the value of the notesource's -->
517 <!-- * @fileref attribute (which is stored in the -->
518 <!-- * earmark uri attribute) as the "contents" for -->
519 <!-- * this endnote/notesource -->
520 <xsl:call-template name="display.uri">
521 <xsl:with-param name="uri" select="@uri"/>
525 <xsl:text> </xsl:text>
527 <!-- * ========================================================= -->
528 <!-- * print the URL for links -->
529 <!-- * ========================================================= -->
530 <!-- * In addition to the notesource contents, if the -->
531 <!-- * notesource is a link, we display the URL for the link. -->
532 <!-- * But for notesources that are imagedata, audiodata, or -->
533 <!-- * videodata instances, we don't want to (re)display the -->
534 <!-- * URL for those here, because for those elements, the -->
535 <!-- * notesource contents are the URL (the value of the -->
536 <!-- * @fileref attribute), and we have already rendered them. -->
538 <!-- * We know an earmark is a link if it has non-empty child -->
539 <!-- * content and a uri attribute; so we check for that -->
540 <!-- * condition here. -->
541 <xsl:if test="*/node() and @uri">
542 <xsl:text>.RS</xsl:text>
543 <xsl:if test="not($list-indent = '')">
544 <xsl:text> </xsl:text>
545 <xsl:value-of select="$list-indent"/>
547 <xsl:text> </xsl:text>
548 <!-- * Add hyphenation suppression in URL output only if -->
549 <!-- * $break.after.slash is also non-zero -->
550 <xsl:if test="$man.hyphenate.urls = 0
551 and $man.break.after.slash = 0">
552 <xsl:call-template name="suppress.hyphenation"/>
553 <xsl:text>\%</xsl:text>
555 <xsl:call-template name="display.uri">
556 <xsl:with-param name="uri" select="@uri"/>
558 <xsl:text> </xsl:text>
559 <xsl:text>.RE</xsl:text>
560 <xsl:text> </xsl:text>
566 <xsl:template name="display.uri">
567 <xsl:param name="uri"/>
569 <xsl:when test="contains($uri, ':')">
570 <!-- * if this URI contains a colon character, it’s probably -->
571 <!-- * an absolute URI with a scheme, so we output it as-is -->
572 <xsl:value-of select="$uri"/>
575 <!-- * otherwise this is probably not an absolute URI, so we -->
576 <!-- * need to prepend $man.base.url.for.relative.links to -->
577 <!-- * give the URI some "context" in man-page output -->
579 select="concat($man.base.url.for.relative.links, $uri)"/>