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 8703 2010-07-06 20:57:06Z nwalsh $
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
263 local-name() != 'simpara' and
265 <!-- * for each node we find as a child of a footnote or -->
266 <!-- * annotation, if it's not a para or a text node, emit a -->
267 <!-- * warning... because in manpages output, we can't render -->
268 <!-- * block-level child content of an endnote properly unless -->
269 <!-- * it's wrapped in a para that has some "prefatory" text -->
270 <xsl:variable name="parent-name" select="local-name(..)"/>
271 <xsl:variable name="endnote-number">
272 <xsl:call-template name="pad-string">
273 <!-- * endnote number may be 2 digits, so pad it with a space -->
274 <!-- * if we have only 1 digit -->
275 <xsl:with-param name="padVar" select="concat('#',$notesource.number)"/>
276 <xsl:with-param name="length" select="3"/>
279 <xsl:call-template name="log.message">
280 <xsl:with-param name="level">Warn</xsl:with-param>
281 <xsl:with-param name="source" select="$refname"/>
282 <xsl:with-param name="context-desc">
283 <xsl:text>endnote </xsl:text>
284 <xsl:value-of select="$endnote-number"/>
286 <xsl:with-param name="message">
287 <xsl:text>Bad: </xsl:text>
288 <xsl:value-of select="$parent-name"/>
289 <!-- * figure out which occurance of this element type this -->
290 <!-- * instance is and output a number in square brackets so -->
291 <!-- * that end-user can know which element to fix -->
292 <xsl:text>[</xsl:text>
293 <xsl:value-of select="count(preceding::*[local-name() = $parent-name]) + 1"/>
294 <xsl:text>]</xsl:text>
295 <xsl:text> in source</xsl:text>
298 <xsl:call-template name="log.message">
299 <xsl:with-param name="level">Note</xsl:with-param>
300 <xsl:with-param name="source" select="$refname"/>
301 <xsl:with-param name="context-desc">
302 <xsl:text>endnote </xsl:text>
303 <xsl:value-of select="$endnote-number"/>
305 <xsl:with-param name="message">
306 <xsl:text>Has: </xsl:text>
307 <xsl:value-of select="$parent-name"/>
308 <xsl:text>/</xsl:text>
309 <xsl:value-of select="local-name(.)"/>
312 <xsl:call-template name="log.message">
313 <xsl:with-param name="level">Note</xsl:with-param>
314 <xsl:with-param name="source" select="$refname"/>
315 <xsl:with-param name="context-desc">
316 <xsl:text>endnote </xsl:text>
317 <xsl:value-of select="$endnote-number"/>
319 <xsl:with-param name="message">
320 <xsl:text>Fix: </xsl:text>
321 <xsl:value-of select="$parent-name"/>
322 <xsl:text>/</xsl:text>
323 <xsl:text>para/</xsl:text>
324 <xsl:value-of select="local-name(.)"/>
332 <!-- * Otherwise this is an empty link or an empty imagedata, -->
333 <!-- * audiodata, or videodata element, so we just get the -->
334 <!-- * value of its url, xlink:href, or fileref attribute. -->
335 <xsl:if test="$man.hyphenate.urls = 0
336 and $man.break.after.slash = 0">
337 <!-- * Add hyphenation suppression in URL output only if -->
338 <!-- * break.after.slash is also non-zero -->
339 <xsl:call-template name="suppress.hyphenation"/>
340 <xsl:text>\%</xsl:text>
342 <xsl:value-of select="$earmark"/>
347 <xsl:if test="self::ulink or self::*[@xlink:href]">
348 <xsl:variable name="link.wrapper">
349 <xsl:value-of select="normalize-space($notesource.contents)"/>
351 <xsl:text>\m[blue]</xsl:text>
352 <!-- * This is a hyperlink, so we need to determine if the user wants -->
353 <!-- * font formatting applied to it, and if so, what font -->
355 <xsl:when test="$man.font.links = 'B'">
356 <xsl:call-template name="bold">
357 <xsl:with-param name="node" select="exsl:node-set($link.wrapper)"/>
358 <xsl:with-param name="context" select="."/>
361 <xsl:when test="$man.font.links = 'I'">
362 <xsl:call-template name="italic">
363 <xsl:with-param name="node" select="exsl:node-set($link.wrapper)"/>
364 <xsl:with-param name="context" select="."/>
367 <xsl:when test="$man.font.links = ''">
368 <!-- * if man.font.links is empty, user doesn't want links -->
369 <!-- * underlined, so just display content -->
370 <xsl:value-of select="$notesource.contents"/>
373 <!-- * otherwise the user has specified an unsupported value for -->
374 <!-- * man.font.links, so emit a warning and don't apply any font -->
375 <!-- * formatting -->
377 <xsl:call-template name="log.message">
378 <xsl:with-param name="level">Warn</xsl:with-param>
379 <xsl:with-param name="source" select="$refname"/>
380 <xsl:with-param name="context-desc">
381 <xsl:text>link font</xsl:text>
383 <xsl:with-param name="message">
384 <xsl:text>invalid $man.font.links value: </xsl:text>
385 <xsl:text>'</xsl:text>
386 <xsl:value-of select="$man.font.links"/>
387 <xsl:text>'</xsl:text>
391 <xsl:value-of select="$notesource.contents"/>
394 <xsl:text>\m[]</xsl:text>
397 <xsl:if test="$notesource.number != ''">
398 <!-- * Format the number by placing it in square brackets. -->
399 <!-- * Also, set the number in font-size -2, and superscripted (\u -->
400 <!-- * means to move up half a line vertically) -->
401 <xsl:text>\&\s-2\u[</xsl:text>
402 <xsl:value-of select="$notesource.number"/>
403 <xsl:text>]\d\s+2</xsl:text>
404 <!-- * Revert superscripting (\d means to move down half a line), and -->
405 <!-- * move the font-size back to what it was before. -->
406 <!-- * Note that the reason for the \& before the opening bracket -->
407 <!-- * is to prevent any possible linebreak from being introduced -->
408 <!-- * between the opening bracket and the following text. -->
412 <!-- ==================================================================== -->
414 <xsl:template name="endnotes.list">
415 <!-- We have stored earmark indexes for all refentry instances in the -->
416 <!-- current document, with the ID for each index being the same ID as -->
417 <!-- its corresponding refentry; so we now need to get the ID for the -->
418 <!-- current refentry so we can grab its corresponding earmark index -->
419 <xsl:variable name="current.refentry.id">
420 <xsl:value-of select="generate-id(.)"/>
423 <xsl:variable name="endnotes.rtf">
424 <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
425 <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
427 <xsl:variable name="all.earmark.indexes.in.current.document"
428 select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
430 select="$all.earmark.indexes.in.current.document/earmark.index
431 [@idref = $current.refentry.id]/earmark"/>
434 <xsl:variable name="endnotes" select="exsl:node-set($endnotes.rtf)"/>
436 <!-- * check to see if we have actually found any content to use as -->
437 <!-- * endnotes; if we have, we generate the endnotes list, if not, -->
438 <!-- * we do nothing -->
439 <xsl:if test="$endnotes/node()">
440 <xsl:call-template name="format.endnotes.list">
441 <xsl:with-param name="endnotes" select="$endnotes"/>
447 <!-- ==================================================================== -->
449 <xsl:template name="format.endnotes.list">
450 <xsl:param name="endnotes"/>
452 <!-- * ======= make the endnotes-list section heading ============= -->
453 <xsl:call-template name="make.subheading">
454 <xsl:with-param name="title">
456 <!-- * if user has specified a heading, use that -->
457 <xsl:when test="$man.endnotes.list.heading != ''">
458 <xsl:value-of select="$man.endnotes.list.heading"/>
461 <!-- * otherwise, get localized heading from gentext -->
462 <!-- * (in English, NOTES) -->
463 <xsl:call-template name="gentext">
464 <xsl:with-param name="key" select="'Notes'"/>
471 <!-- * ================ process each earmark ====================== -->
472 <xsl:for-each select="$endnotes/earmark">
473 <!-- * make paragraph with hanging indent, and starting with a -->
474 <!-- * number in the form " 1." (padded to $man.indent.width - 1) -->
475 <xsl:text>.IP</xsl:text>
476 <xsl:text> "</xsl:text>
477 <xsl:variable name="endnote.number">
478 <xsl:value-of select="@number"/>
479 <xsl:text>.</xsl:text>
481 <xsl:call-template name="pad-string">
482 <xsl:with-param name="padVar" select="$endnote.number"/>
483 <!-- FIXME: the following assumes that $man.indent.width is in -->
484 <!-- en's; also, this should probably use $list.indent instead -->
485 <xsl:with-param name="length" select="$man.indent.width - 1"/>
487 <xsl:text>"</xsl:text>
488 <xsl:if test="not($list-indent = '')">
489 <xsl:text> </xsl:text>
490 <xsl:value-of select="$list-indent"/>
492 <xsl:text> </xsl:text>
494 <!-- * ========================================================= -->
495 <!-- * print the notesource/endnote contents -->
496 <!-- * ========================================================= -->
498 <xsl:when test="*/node()">
499 <!-- * if the earmark has non-empty child content, then -->
500 <!-- * its corresponding notesource is either a link or -->
501 <!-- * an instance of annotative text, so we want to -->
502 <!-- * display that content -->
504 <xsl:when test="*/node()[name(.)!='']">
505 <!-- * if node is not text only, then process it as-is -->
506 <xsl:apply-templates select="*/node()"/>
509 <!-- * otherwise node is text-only, so normalize it -->
510 <xsl:value-of select="normalize-space(*/node())"/>
515 <!-- * otherwise, this earmark has empty content, -->
516 <!-- * which means its corresponding notesource is an -->
517 <!-- * imagedata, audiodata, or videodata instance; in -->
518 <!-- * that case, we use the value of the notesource's -->
519 <!-- * @fileref attribute (which is stored in the -->
520 <!-- * earmark uri attribute) as the "contents" for -->
521 <!-- * this endnote/notesource -->
522 <xsl:call-template name="display.uri">
523 <xsl:with-param name="uri" select="@uri"/>
527 <xsl:text> </xsl:text>
529 <!-- * ========================================================= -->
530 <!-- * print the URL for links -->
531 <!-- * ========================================================= -->
532 <!-- * In addition to the notesource contents, if the -->
533 <!-- * notesource is a link, we display the URL for the link. -->
534 <!-- * But for notesources that are imagedata, audiodata, or -->
535 <!-- * videodata instances, we don't want to (re)display the -->
536 <!-- * URL for those here, because for those elements, the -->
537 <!-- * notesource contents are the URL (the value of the -->
538 <!-- * @fileref attribute), and we have already rendered them. -->
540 <!-- * We know an earmark is a link if it has non-empty child -->
541 <!-- * content and a uri attribute; so we check for that -->
542 <!-- * condition here. -->
543 <xsl:if test="*/node() and @uri">
544 <xsl:text>.RS</xsl:text>
545 <xsl:if test="not($list-indent = '')">
546 <xsl:text> </xsl:text>
547 <xsl:value-of select="$list-indent"/>
549 <xsl:text> </xsl:text>
550 <!-- * Add hyphenation suppression in URL output only if -->
551 <!-- * $break.after.slash is also non-zero -->
552 <xsl:if test="$man.hyphenate.urls = 0
553 and $man.break.after.slash = 0">
554 <xsl:call-template name="suppress.hyphenation"/>
555 <xsl:text>\%</xsl:text>
557 <xsl:call-template name="display.uri">
558 <xsl:with-param name="uri" select="@uri"/>
560 <xsl:text> </xsl:text>
561 <xsl:text>.RE</xsl:text>
562 <xsl:text> </xsl:text>
568 <xsl:template name="display.uri">
569 <xsl:param name="uri"/>
571 <xsl:when test="contains($uri, ':')">
572 <!-- * if this URI contains a colon character, it’s probably -->
573 <!-- * an absolute URI with a scheme, so we output it as-is -->
574 <xsl:value-of select="$uri"/>
577 <!-- * otherwise this is probably not an absolute URI, so we -->
578 <!-- * need to prepend $man.base.url.for.relative.links to -->
579 <!-- * give the URI some "context" in man-page output -->
581 select="concat($man.base.url.for.relative.links, $uri)"/>