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,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 <!-- ==================================================================== -->
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 whose string -->
46 <!-- * value is identical to 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 <!-- * 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=
"all.earmark.indexes.in.current.document.rtf">
182 <xsl:call-template name=
"get.all.earmark.indexes.in.current.document"/>
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 -->
190 select=
"$all.earmark.indexes.in.current.document/earmark.index
192 generate-id(current()/ancestor::refentry)]/earmark"/>
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">
200 <xsl:when test=
"@url|@xlink:href">
201 <xsl:value-of select=
"@url|@xlink:href"/>
203 <xsl:when test=
"@fileref">
204 <xsl:value-of select=
"@fileref"/>
207 <xsl:value-of select=
"generate-id()"/>
212 <xsl:variable name=
"notesource.contents">
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/>
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. -->
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>
231 <xsl:value-of select=
"$earmark"/>
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). -->
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>
245 <xsl:apply-templates mode=
"italic"
246 select=
"exsl:node-set($link.wrapper)"/>
249 <!-- * user doesn't want links underlined, so just display content -->
250 <xsl:value-of select=
"$notesource.contents"/>
255 <!-- * Format the numbered marker for this notesource -->
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
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. -->
277 <xsl:variable name=
"notesource.number">
279 <xsl:when test=
"self::ulink or
280 self::*[@xlink:href] or
284 <xsl:value-of select=
"$all.earmarks.in.current.refentry/earmark[@uri = $earmark]/@number"/>
287 <xsl:value-of select=
"$all.earmarks.in.current.refentry/earmark[@id = $earmark]/@number"/>
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>\
&[
</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. -->
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(.)"/>
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"/>
320 <xsl:variable name=
"all.earmark.indexes.in.current.document"
321 select=
"exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
323 select=
"$all.earmark.indexes.in.current.document/earmark.index
324 [@idref = $current.refentry.id]/earmark"/>
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"/>
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
">
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
"/>
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'
"/>
365 <xsl:text>" </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>
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"/>
383 <xsl:text>"</xsl:text>
384 <xsl:if test=
"not($list-indent = '')">
385 <xsl:text> </xsl:text>
386 <xsl:value-of select=
"$list-indent"/>
388 <xsl:text> </xsl:text>
390 <!-- * ========================================================= -->
391 <!-- * print the notesource/endnote contents -->
392 <!-- * ========================================================= -->
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()"/>
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"/>
412 <xsl:text> </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. -->
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"/>
434 <xsl:text> </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>
442 <xsl:value-of select=
"@uri"/>
443 <xsl:text> </xsl:text>
444 <xsl:text>.RE
</xsl:text>
445 <xsl:text> </xsl:text>