1
0

endnotes.xsl 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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. $Id: endnotes.xsl 8703 2010-07-06 20:57:06Z nwalsh $
  11. ********************************************************************
  12. This file is part of the XSL DocBook Stylesheet distribution.
  13. See ../README or http://docbook.sf.net/release/xsl/current/ for
  14. copyright and other information.
  15. ******************************************************************** -->
  16. <!-- ==================================================================== -->
  17. <!-- * -->
  18. <!-- * The templates in this file handle elements whose contents can't -->
  19. <!-- * be displayed completely within the main text flow in output, but -->
  20. <!-- * instead need to be displayed "out of line". Those elements are: -->
  21. <!-- * -->
  22. <!-- * - elements providing annotative text (annotation|alt|footnote) -->
  23. <!-- * - elements pointing at external resources (ulink, link, and -->
  24. <!-- * any elements with xlink:href attributes; and imagedata, -->
  25. <!-- * audiodata, and videodata - which (using their fileref -->
  26. <!-- * attribute) reference external files -->
  27. <!-- * -->
  28. <!-- * Within this stylesheet, the above are collectively referred to as -->
  29. <!-- * a "notesources". This stylesheet handles those notesources in -->
  30. <!-- * this way: -->
  31. <!-- * -->
  32. <!-- * 1. Constructs a numbered in-memory index of all unique "earmarks“ -->
  33. <!-- * of all notesources in the document. For each link, the -->
  34. <!-- * earmark is the value of its url or xlink:href attribute; for -->
  35. <!-- * each imagedata|audiodata|videodata: the value of its fileref -->
  36. <!-- * attribute; for each annotative element: its content. -->
  37. <!-- * -->
  38. <!-- * Notesources with the same earmark are assigned the same -->
  39. <!-- * number. -->
  40. <!-- * -->
  41. <!-- * By design, that index excludes any element whose string value -->
  42. <!-- * is identical to the value of its url xlink:href attribute). -->
  43. <!-- * -->
  44. <!-- * 2. Puts a numbered marker inline to mark the place where the -->
  45. <!-- * notesource occurs in the main text flow. -->
  46. <!-- * -->
  47. <!-- * 3. Generates a numbered endnotes list (titled NOTES in English) -->
  48. <!-- * at the end of the man page, with the contents of each -->
  49. <!-- * notesource. -->
  50. <!-- * -->
  51. <!-- * Note that table footnotes are not listed in the endnotes list, -->
  52. <!-- * and are not handled by this stylesheet (they are instead handled -->
  53. <!-- * by the table.xsl stylesheet). -->
  54. <!-- * -->
  55. <!-- * Also, we don't get notesources in *info sections or Refmeta or -->
  56. <!-- * Refnamediv or Indexterm, because, in manpages output, contents of -->
  57. <!-- * those are either suppressed or are displayed out of document -->
  58. <!-- * order - for example, the Info/Author content gets moved to the -->
  59. <!-- * end of the page. So, if we were to number notesources in the -->
  60. <!-- * Author content, it would "throw off" the numbering at the -->
  61. <!-- * beginning of the main text flow. -->
  62. <!-- * -->
  63. <!-- * And for the record, one reason we don't use xsl:key to index the -->
  64. <!-- * earmarks is that we need to get and check the sets of -->
  65. <!-- * earmarks for uniqueness per-Refentry (not per-document). -->
  66. <!-- * -->
  67. <!-- * FIXME: -->
  68. <!-- * as with "repeat" URLS, alt instances that have the same string value -->
  69. <!-- * as preceding ones (likely to occur for repeat acroynyms and -->
  70. <!-- * abbreviations) should be listed only once in the endnotes list, -->
  71. <!-- * and numbered accordingly inline; split man.indent.width into -->
  72. <!-- * man.indent.width.value (default 4) and man.indent.width.units -->
  73. <!-- * (default n); also, if the first child of notesource is some block -->
  74. <!-- * content other than a (non-formal) paragraph, the current code -->
  75. <!-- * will probably end up generating a blank line after the -->
  76. <!-- * corresponding number in the endnotes list... we should probably -->
  77. <!-- * try to instead display the title of that block content there (if -->
  78. <!-- * there is one: e.g., the list title, admonition title, etc.) -->
  79. <!-- ==================================================================== -->
  80. <xsl:template name="get.all.earmark.indexes.in.current.document">
  81. <!-- * Here we create a tree to hold indexes of all earmarks in -->
  82. <!-- * the current document. If the current document contains -->
  83. <!-- * multiple refentry instances, then this tree will contain -->
  84. <!-- * multiple indexes. -->
  85. <xsl:if test="$man.endnotes.are.numbered != 0">
  86. <!-- * Only create earmark indexes if user wants numbered endnotes -->
  87. <xsl:for-each select="//refentry">
  88. <earmark.index>
  89. <xsl:attribute name="idref">
  90. <xsl:value-of select="generate-id()"/>
  91. </xsl:attribute>
  92. <xsl:for-each
  93. select=".//*[self::*[@xlink:href]
  94. or self::ulink
  95. or self::imagedata
  96. or self::audiodata
  97. or self::videodata
  98. or self::footnote[not(ancestor::table)]
  99. or self::annotation
  100. or self::alt]
  101. [(node()
  102. or self::imagedata
  103. or self::audiodata
  104. or self::videodata
  105. )
  106. and not(ancestor::refentryinfo)
  107. and not(ancestor::info)
  108. and not(ancestor::docinfo)
  109. and not(ancestor::refmeta)
  110. and not(ancestor::refnamediv)
  111. and not(ancestor::indexterm)
  112. and not(. = @url)
  113. and not(. = @xlink:href)
  114. and not(@url =
  115. preceding::ulink[node()
  116. and not(ancestor::refentryinfo)
  117. and not(ancestor::info)
  118. and not(ancestor::docinfo)
  119. and not(ancestor::refmeta)
  120. and not(ancestor::refnamediv)
  121. and not(ancestor::indexterm)
  122. and (generate-id(ancestor::refentry)
  123. = generate-id(current()))]/@url)
  124. and not(@xlink:href =
  125. preceding::*[@xlink:href][node()
  126. and not(ancestor::refentryinfo)
  127. and not(ancestor::info)
  128. and not(ancestor::docinfo)
  129. and not(ancestor::refmeta)
  130. and not(ancestor::refnamediv)
  131. and not(ancestor::indexterm)
  132. and (generate-id(ancestor::refentry)
  133. = generate-id(current()))]/@xlink:href)
  134. and not(@fileref =
  135. preceding::*[@fileref][
  136. not(ancestor::refentryinfo)
  137. and not(ancestor::info)
  138. and not(ancestor::docinfo)
  139. and not(ancestor::refmeta)
  140. and not(ancestor::refnamediv)
  141. and not(ancestor::indexterm)
  142. and (generate-id(ancestor::refentry)
  143. = generate-id(current()))]/@fileref)]">
  144. <earmark>
  145. <xsl:attribute name="id">
  146. <xsl:value-of select="generate-id()"/>
  147. </xsl:attribute>
  148. <xsl:attribute name="number">
  149. <xsl:value-of select="position()"/>
  150. </xsl:attribute>
  151. <xsl:if test="@url|@xlink:href|@fileref">
  152. <!-- * Only add a uri attribute if the notesource is -->
  153. <!-- * a link or an element that references an external -->
  154. <!-- * (an imagedata, audiodata, or videodata element) -->
  155. <xsl:attribute name="uri">
  156. <xsl:value-of select="@url|@xlink:href|@fileref"/>
  157. </xsl:attribute>
  158. </xsl:if>
  159. <xsl:copy>
  160. <xsl:copy-of select="node()"/>
  161. </xsl:copy>
  162. </earmark>
  163. </xsl:for-each>
  164. </earmark.index>
  165. </xsl:for-each>
  166. </xsl:if>
  167. </xsl:template>
  168. <!-- ==================================================================== -->
  169. <xsl:template match="*[@xlink:href]|ulink
  170. |imagedata|audiodata|videodata
  171. |footnote[not(ancestor::table)]
  172. |annotation|alt">
  173. <xsl:variable name="refname" select="ancestor::refentry/refnamediv[1]/refname[1]"/>
  174. <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
  175. <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
  176. </xsl:variable>
  177. <xsl:variable name="all.earmark.indexes.in.current.document"
  178. select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
  179. <xsl:variable name="all.earmarks.in.current.refentry.rtf">
  180. <!-- * get the set of all earmarks for the ancestor Refentry of -->
  181. <!-- * this notesource -->
  182. <xsl:copy-of
  183. select="$all.earmark.indexes.in.current.document/earmark.index
  184. [@idref =
  185. generate-id(current()/ancestor::refentry)]/earmark"/>
  186. </xsl:variable>
  187. <xsl:variable name="all.earmarks.in.current.refentry"
  188. select="exsl:node-set($all.earmarks.in.current.refentry.rtf)"/>
  189. <!-- * identify the earmark for the current element -->
  190. <xsl:variable name="earmark">
  191. <xsl:choose>
  192. <xsl:when test="@url|@xlink:href">
  193. <xsl:value-of select="@url|@xlink:href"/>
  194. </xsl:when>
  195. <xsl:when test="@fileref">
  196. <xsl:value-of select="@fileref"/>
  197. </xsl:when>
  198. <xsl:otherwise>
  199. <xsl:value-of select="generate-id()"/>
  200. </xsl:otherwise>
  201. </xsl:choose>
  202. </xsl:variable>
  203. <xsl:variable name="notesource.number">
  204. <!-- * Get the number for this notesource -->
  205. <!-- * -->
  206. <!-- * If this is an imagedata, audiodata, or videodata element -->
  207. <!-- * OR if it's a non-empty element AND its string value is not -->
  208. <!-- * equal to the value of its url or xlink:href attribute (if -->
  209. <!-- * it has one) AND user wants endnotes numbered, only then -->
  210. <!-- * do we output a number for it -->
  211. <xsl:if test="(self::imagedata or
  212. self::audiodata or
  213. self::videodata or
  214. (node()
  215. and not(. = @url)
  216. and not(. = @xlink:href))
  217. )
  218. and $man.endnotes.are.numbered != 0">
  219. <!-- * To select the number for this notesource, we -->
  220. <!-- * check the index of all earmarks for the current refentry -->
  221. <!-- * and find the number of the indexed earmark which matches -->
  222. <!-- * this notesource's earmark. -->
  223. <!-- * Note that multiple notesources may share the same -->
  224. <!-- * numbered earmark; in that case, they get the same number. -->
  225. <!-- * -->
  226. <xsl:choose>
  227. <xsl:when test="self::ulink or
  228. self::*[@xlink:href] or
  229. self::imagedata or
  230. self::audiodata or
  231. self::videodata">
  232. <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@uri = $earmark]/@number"/>
  233. </xsl:when>
  234. <xsl:otherwise>
  235. <xsl:value-of select="$all.earmarks.in.current.refentry/earmark[@id = $earmark]/@number"/>
  236. </xsl:otherwise>
  237. </xsl:choose>
  238. </xsl:if>
  239. </xsl:variable>
  240. <xsl:variable name="notesource.contents">
  241. <xsl:choose>
  242. <!-- * check to see if the element is empty or not -->
  243. <xsl:when test="node()">
  244. <!-- * this is a non-empty node, so process its contents -->
  245. <xsl:apply-templates/>
  246. <xsl:if test="../footnote or ../annotation">
  247. <!-- * if this element is a footnote or annotation, we need to -->
  248. <!-- * do some further checking on it, so we can emit warnings -->
  249. <!-- * about potential problems -->
  250. <xsl:for-each select="node()">
  251. <xsl:if test="local-name() != 'para' and
  252. local-name() != 'simpara' and
  253. local-name() !=''">
  254. <!-- * for each node we find as a child of a footnote or -->
  255. <!-- * annotation, if it's not a para or a text node, emit a -->
  256. <!-- * warning... because in manpages output, we can't render -->
  257. <!-- * block-level child content of an endnote properly unless -->
  258. <!-- * it's wrapped in a para that has some "prefatory" text -->
  259. <xsl:variable name="parent-name" select="local-name(..)"/>
  260. <xsl:variable name="endnote-number">
  261. <xsl:call-template name="pad-string">
  262. <!-- * endnote number may be 2 digits, so pad it with a space -->
  263. <!-- * if we have only 1 digit -->
  264. <xsl:with-param name="padVar" select="concat('#',$notesource.number)"/>
  265. <xsl:with-param name="length" select="3"/>
  266. </xsl:call-template>
  267. </xsl:variable>
  268. <xsl:call-template name="log.message">
  269. <xsl:with-param name="level">Warn</xsl:with-param>
  270. <xsl:with-param name="source" select="$refname"/>
  271. <xsl:with-param name="context-desc">
  272. <xsl:text>endnote </xsl:text>
  273. <xsl:value-of select="$endnote-number"/>
  274. </xsl:with-param>
  275. <xsl:with-param name="message">
  276. <xsl:text>Bad: </xsl:text>
  277. <xsl:value-of select="$parent-name"/>
  278. <!-- * figure out which occurance of this element type this -->
  279. <!-- * instance is and output a number in square brackets so -->
  280. <!-- * that end-user can know which element to fix -->
  281. <xsl:text>[</xsl:text>
  282. <xsl:value-of select="count(preceding::*[local-name() = $parent-name]) + 1"/>
  283. <xsl:text>]</xsl:text>
  284. <xsl:text> in source</xsl:text>
  285. </xsl:with-param>
  286. </xsl:call-template>
  287. <xsl:call-template name="log.message">
  288. <xsl:with-param name="level">Note</xsl:with-param>
  289. <xsl:with-param name="source" select="$refname"/>
  290. <xsl:with-param name="context-desc">
  291. <xsl:text>endnote </xsl:text>
  292. <xsl:value-of select="$endnote-number"/>
  293. </xsl:with-param>
  294. <xsl:with-param name="message">
  295. <xsl:text>Has: </xsl:text>
  296. <xsl:value-of select="$parent-name"/>
  297. <xsl:text>/</xsl:text>
  298. <xsl:value-of select="local-name(.)"/>
  299. </xsl:with-param>
  300. </xsl:call-template>
  301. <xsl:call-template name="log.message">
  302. <xsl:with-param name="level">Note</xsl:with-param>
  303. <xsl:with-param name="source" select="$refname"/>
  304. <xsl:with-param name="context-desc">
  305. <xsl:text>endnote </xsl:text>
  306. <xsl:value-of select="$endnote-number"/>
  307. </xsl:with-param>
  308. <xsl:with-param name="message">
  309. <xsl:text>Fix: </xsl:text>
  310. <xsl:value-of select="$parent-name"/>
  311. <xsl:text>/</xsl:text>
  312. <xsl:text>para/</xsl:text>
  313. <xsl:value-of select="local-name(.)"/>
  314. </xsl:with-param>
  315. </xsl:call-template>
  316. </xsl:if>
  317. </xsl:for-each>
  318. </xsl:if>
  319. </xsl:when>
  320. <xsl:otherwise>
  321. <!-- * Otherwise this is an empty link or an empty imagedata, -->
  322. <!-- * audiodata, or videodata element, so we just get the -->
  323. <!-- * value of its url, xlink:href, or fileref attribute. -->
  324. <xsl:if test="$man.hyphenate.urls = 0
  325. and $man.break.after.slash = 0">
  326. <!-- * Add hyphenation suppression in URL output only if -->
  327. <!-- * break.after.slash is also non-zero -->
  328. <xsl:call-template name="suppress.hyphenation"/>
  329. <xsl:text>\%</xsl:text>
  330. </xsl:if>
  331. <xsl:value-of select="$earmark"/>
  332. </xsl:otherwise>
  333. </xsl:choose>
  334. </xsl:variable>
  335. <xsl:if test="self::ulink or self::*[@xlink:href]">
  336. <xsl:variable name="link.wrapper">
  337. <xsl:value-of select="normalize-space($notesource.contents)"/>
  338. </xsl:variable>
  339. <xsl:text>\m[blue]</xsl:text>
  340. <!-- * This is a hyperlink, so we need to determine if the user wants -->
  341. <!-- * font formatting applied to it, and if so, what font -->
  342. <xsl:choose>
  343. <xsl:when test="$man.font.links = 'B'">
  344. <xsl:call-template name="bold">
  345. <xsl:with-param name="node" select="exsl:node-set($link.wrapper)"/>
  346. <xsl:with-param name="context" select="."/>
  347. </xsl:call-template>
  348. </xsl:when>
  349. <xsl:when test="$man.font.links = 'I'">
  350. <xsl:call-template name="italic">
  351. <xsl:with-param name="node" select="exsl:node-set($link.wrapper)"/>
  352. <xsl:with-param name="context" select="."/>
  353. </xsl:call-template>
  354. </xsl:when>
  355. <xsl:when test="$man.font.links = ''">
  356. <!-- * if man.font.links is empty, user doesn't want links -->
  357. <!-- * underlined, so just display content -->
  358. <xsl:value-of select="$notesource.contents"/>
  359. </xsl:when>
  360. <xsl:otherwise>
  361. <!-- * otherwise the user has specified an unsupported value for -->
  362. <!-- * man.font.links, so emit a warning and don't apply any font -->
  363. <!-- * formatting -->
  364. <xsl:message>
  365. <xsl:call-template name="log.message">
  366. <xsl:with-param name="level">Warn</xsl:with-param>
  367. <xsl:with-param name="source" select="$refname"/>
  368. <xsl:with-param name="context-desc">
  369. <xsl:text>link font</xsl:text>
  370. </xsl:with-param>
  371. <xsl:with-param name="message">
  372. <xsl:text>invalid $man.font.links value: </xsl:text>
  373. <xsl:text>'</xsl:text>
  374. <xsl:value-of select="$man.font.links"/>
  375. <xsl:text>'</xsl:text>
  376. </xsl:with-param>
  377. </xsl:call-template>
  378. </xsl:message>
  379. <xsl:value-of select="$notesource.contents"/>
  380. </xsl:otherwise>
  381. </xsl:choose>
  382. <xsl:text>\m[]</xsl:text>
  383. </xsl:if>
  384. <xsl:if test="$notesource.number != ''">
  385. <!-- * Format the number by placing it in square brackets. -->
  386. <!-- * Also, set the number in font-size -2, and superscripted (\u -->
  387. <!-- * means to move up half a line vertically) -->
  388. <xsl:text>\&amp;\s-2\u[</xsl:text>
  389. <xsl:value-of select="$notesource.number"/>
  390. <xsl:text>]\d\s+2</xsl:text>
  391. <!-- * Revert superscripting (\d means to move down half a line), and -->
  392. <!-- * move the font-size back to what it was before. -->
  393. <!-- * Note that the reason for the \& before the opening bracket -->
  394. <!-- * is to prevent any possible linebreak from being introduced -->
  395. <!-- * between the opening bracket and the following text. -->
  396. </xsl:if>
  397. </xsl:template>
  398. <!-- ==================================================================== -->
  399. <xsl:template name="endnotes.list">
  400. <!-- We have stored earmark indexes for all refentry instances in the -->
  401. <!-- current document, with the ID for each index being the same ID as -->
  402. <!-- its corresponding refentry; so we now need to get the ID for the -->
  403. <!-- current refentry so we can grab its corresponding earmark index -->
  404. <xsl:variable name="current.refentry.id">
  405. <xsl:value-of select="generate-id(.)"/>
  406. </xsl:variable>
  407. <xsl:variable name="endnotes.rtf">
  408. <xsl:variable name="all.earmark.indexes.in.current.document.rtf">
  409. <xsl:call-template name="get.all.earmark.indexes.in.current.document"/>
  410. </xsl:variable>
  411. <xsl:variable name="all.earmark.indexes.in.current.document"
  412. select="exsl:node-set($all.earmark.indexes.in.current.document.rtf)"/>
  413. <xsl:copy-of
  414. select="$all.earmark.indexes.in.current.document/earmark.index
  415. [@idref = $current.refentry.id]/earmark"/>
  416. </xsl:variable>
  417. <xsl:variable name="endnotes" select="exsl:node-set($endnotes.rtf)"/>
  418. <!-- * check to see if we have actually found any content to use as -->
  419. <!-- * endnotes; if we have, we generate the endnotes list, if not, -->
  420. <!-- * we do nothing -->
  421. <xsl:if test="$endnotes/node()">
  422. <xsl:call-template name="format.endnotes.list">
  423. <xsl:with-param name="endnotes" select="$endnotes"/>
  424. </xsl:call-template>
  425. </xsl:if>
  426. </xsl:template>
  427. <!-- ==================================================================== -->
  428. <xsl:template name="format.endnotes.list">
  429. <xsl:param name="endnotes"/>
  430. <!-- * ======= make the endnotes-list section heading ============= -->
  431. <xsl:call-template name="make.subheading">
  432. <xsl:with-param name="title">
  433. <xsl:choose>
  434. <!-- * if user has specified a heading, use that -->
  435. <xsl:when test="$man.endnotes.list.heading != ''">
  436. <xsl:value-of select="$man.endnotes.list.heading"/>
  437. </xsl:when>
  438. <xsl:otherwise>
  439. <!-- * otherwise, get localized heading from gentext -->
  440. <!-- * (in English, NOTES) -->
  441. <xsl:call-template name="gentext">
  442. <xsl:with-param name="key" select="'Notes'"/>
  443. </xsl:call-template>
  444. </xsl:otherwise>
  445. </xsl:choose>
  446. </xsl:with-param>
  447. </xsl:call-template>
  448. <!-- * ================ process each earmark ====================== -->
  449. <xsl:for-each select="$endnotes/earmark">
  450. <!-- * make paragraph with hanging indent, and starting with a -->
  451. <!-- * number in the form " 1." (padded to $man.indent.width - 1) -->
  452. <xsl:text>.IP</xsl:text>
  453. <xsl:text> "</xsl:text>
  454. <xsl:variable name="endnote.number">
  455. <xsl:value-of select="@number"/>
  456. <xsl:text>.</xsl:text>
  457. </xsl:variable>
  458. <xsl:call-template name="pad-string">
  459. <xsl:with-param name="padVar" select="$endnote.number"/>
  460. <!-- FIXME: the following assumes that $man.indent.width is in -->
  461. <!-- en's; also, this should probably use $list.indent instead -->
  462. <xsl:with-param name="length" select="$man.indent.width - 1"/>
  463. </xsl:call-template>
  464. <xsl:text>"</xsl:text>
  465. <xsl:if test="not($list-indent = '')">
  466. <xsl:text> </xsl:text>
  467. <xsl:value-of select="$list-indent"/>
  468. </xsl:if>
  469. <xsl:text>&#10;</xsl:text>
  470. <!-- * ========================================================= -->
  471. <!-- * print the notesource/endnote contents -->
  472. <!-- * ========================================================= -->
  473. <xsl:choose>
  474. <xsl:when test="*/node()">
  475. <!-- * if the earmark has non-empty child content, then -->
  476. <!-- * its corresponding notesource is either a link or -->
  477. <!-- * an instance of annotative text, so we want to -->
  478. <!-- * display that content -->
  479. <xsl:choose>
  480. <xsl:when test="*/node()[name(.)!='']">
  481. <!-- * if node is not text only, then process it as-is -->
  482. <xsl:apply-templates select="*/node()"/>
  483. </xsl:when>
  484. <xsl:otherwise>
  485. <!-- * otherwise node is text-only, so normalize it -->
  486. <xsl:value-of select="normalize-space(*/node())"/>
  487. </xsl:otherwise>
  488. </xsl:choose>
  489. </xsl:when>
  490. <xsl:otherwise>
  491. <!-- * otherwise, this earmark has empty content, -->
  492. <!-- * which means its corresponding notesource is an -->
  493. <!-- * imagedata, audiodata, or videodata instance; in -->
  494. <!-- * that case, we use the value of the notesource's -->
  495. <!-- * @fileref attribute (which is stored in the -->
  496. <!-- * earmark uri attribute) as the "contents" for -->
  497. <!-- * this endnote/notesource -->
  498. <xsl:call-template name="display.uri">
  499. <xsl:with-param name="uri" select="@uri"/>
  500. </xsl:call-template>
  501. </xsl:otherwise>
  502. </xsl:choose>
  503. <xsl:text>&#10;</xsl:text>
  504. <!-- * ========================================================= -->
  505. <!-- * print the URL for links -->
  506. <!-- * ========================================================= -->
  507. <!-- * In addition to the notesource contents, if the -->
  508. <!-- * notesource is a link, we display the URL for the link. -->
  509. <!-- * But for notesources that are imagedata, audiodata, or -->
  510. <!-- * videodata instances, we don't want to (re)display the -->
  511. <!-- * URL for those here, because for those elements, the -->
  512. <!-- * notesource contents are the URL (the value of the -->
  513. <!-- * @fileref attribute), and we have already rendered them. -->
  514. <!-- * -->
  515. <!-- * We know an earmark is a link if it has non-empty child -->
  516. <!-- * content and a uri attribute; so we check for that -->
  517. <!-- * condition here. -->
  518. <xsl:if test="*/node() and @uri">
  519. <xsl:text>.RS</xsl:text>
  520. <xsl:if test="not($list-indent = '')">
  521. <xsl:text> </xsl:text>
  522. <xsl:value-of select="$list-indent"/>
  523. </xsl:if>
  524. <xsl:text>&#10;</xsl:text>
  525. <!-- * Add hyphenation suppression in URL output only if -->
  526. <!-- * $break.after.slash is also non-zero -->
  527. <xsl:if test="$man.hyphenate.urls = 0
  528. and $man.break.after.slash = 0">
  529. <xsl:call-template name="suppress.hyphenation"/>
  530. <xsl:text>\%</xsl:text>
  531. </xsl:if>
  532. <xsl:call-template name="display.uri">
  533. <xsl:with-param name="uri" select="@uri"/>
  534. </xsl:call-template>
  535. <xsl:text>&#10;</xsl:text>
  536. <xsl:text>.RE</xsl:text>
  537. <xsl:text>&#10;</xsl:text>
  538. </xsl:if>
  539. </xsl:for-each>
  540. </xsl:template>
  541. <xsl:template name="display.uri">
  542. <xsl:param name="uri"/>
  543. <xsl:choose>
  544. <xsl:when test="contains($uri, ':')">
  545. <!-- * if this URI contains a colon character, it’s probably -->
  546. <!-- * an absolute URI with a scheme, so we output it as-is -->
  547. <xsl:value-of select="$uri"/>
  548. </xsl:when>
  549. <xsl:otherwise>
  550. <!-- * otherwise this is probably not an absolute URI, so we -->
  551. <!-- * need to prepend $man.base.url.for.relative.links to -->
  552. <!-- * give the URI some "context" in man-page output -->
  553. <xsl:value-of
  554. select="concat($man.base.url.for.relative.links, $uri)"/>
  555. </xsl:otherwise>
  556. </xsl:choose>
  557. </xsl:template>
  558. </xsl:stylesheet>