glossary.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <?xml version='1.0'?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY % common.entities SYSTEM "../common/entities.ent">
  4. %common.entities;
  5. ]>
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:xlink='http://www.w3.org/1999/xlink'
  8. exclude-result-prefixes="xlink"
  9. version='1.0'>
  10. <!-- ********************************************************************
  11. $Id: glossary.xsl 9709 2013-01-22 18:56:09Z bobstayton $
  12. ********************************************************************
  13. This file is part of the XSL DocBook Stylesheet distribution.
  14. See ../README or http://docbook.sf.net/release/xsl/current/ for
  15. copyright and other information.
  16. ******************************************************************** -->
  17. <!-- ==================================================================== -->
  18. <xsl:template match="glossary">
  19. &setup-language-variable;
  20. <xsl:call-template name="id.warning"/>
  21. <xsl:element name="{$div.element}">
  22. <xsl:apply-templates select="." mode="common.html.attributes"/>
  23. <xsl:call-template name="id.attribute">
  24. <xsl:with-param name="conditional" select="0"/>
  25. </xsl:call-template>
  26. <xsl:call-template name="glossary.titlepage"/>
  27. <xsl:choose>
  28. <xsl:when test="glossdiv">
  29. <xsl:apply-templates select="(glossdiv[1]/preceding-sibling::*)"/>
  30. </xsl:when>
  31. <xsl:when test="glossentry">
  32. <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
  33. </xsl:when>
  34. <xsl:otherwise>
  35. <xsl:apply-templates/>
  36. </xsl:otherwise>
  37. </xsl:choose>
  38. <xsl:choose>
  39. <xsl:when test="glossdiv">
  40. <xsl:apply-templates select="glossdiv"/>
  41. </xsl:when>
  42. <xsl:when test="glossentry">
  43. <dl>
  44. <xsl:choose>
  45. <xsl:when test="$glossary.sort != 0">
  46. <xsl:apply-templates select="glossentry">
  47. <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
  48. </xsl:apply-templates>
  49. </xsl:when>
  50. <xsl:otherwise>
  51. <xsl:apply-templates select="glossentry"/>
  52. </xsl:otherwise>
  53. </xsl:choose>
  54. </dl>
  55. </xsl:when>
  56. <xsl:otherwise>
  57. <!-- empty glossary -->
  58. </xsl:otherwise>
  59. </xsl:choose>
  60. <xsl:if test="not(parent::article)">
  61. <xsl:call-template name="process.footnotes"/>
  62. </xsl:if>
  63. </xsl:element>
  64. </xsl:template>
  65. <xsl:template match="glossary/glossaryinfo"></xsl:template>
  66. <xsl:template match="glossary/info"></xsl:template>
  67. <xsl:template match="glossary/title"></xsl:template>
  68. <xsl:template match="glossary/subtitle"></xsl:template>
  69. <xsl:template match="glossary/titleabbrev"></xsl:template>
  70. <!-- ==================================================================== -->
  71. <xsl:template match="glosslist">
  72. &setup-language-variable;
  73. <div>
  74. <xsl:apply-templates select="." mode="common.html.attributes"/>
  75. <xsl:call-template name="id.attribute"/>
  76. <xsl:call-template name="anchor"/>
  77. <xsl:if test="blockinfo/title|info/title|title">
  78. <xsl:call-template name="formal.object.heading"/>
  79. </xsl:if>
  80. <dl>
  81. <xsl:choose>
  82. <xsl:when test="$glossary.sort != 0">
  83. <xsl:apply-templates select="glossentry">
  84. <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
  85. </xsl:apply-templates>
  86. </xsl:when>
  87. <xsl:otherwise>
  88. <xsl:apply-templates select="glossentry"/>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. </dl>
  92. </div>
  93. </xsl:template>
  94. <!-- ==================================================================== -->
  95. <xsl:template match="glossdiv">
  96. &setup-language-variable;
  97. <xsl:call-template name="id.warning"/>
  98. <div>
  99. <xsl:apply-templates select="." mode="common.html.attributes"/>
  100. <xsl:call-template name="id.attribute">
  101. <xsl:with-param name="conditional" select="0"/>
  102. </xsl:call-template>
  103. <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
  104. <dl>
  105. <xsl:choose>
  106. <xsl:when test="$glossary.sort != 0">
  107. <xsl:apply-templates select="glossentry">
  108. <xsl:sort lang="{$language}"
  109. select="translate(glossterm, $lowercase,
  110. $uppercase)"/>
  111. </xsl:apply-templates>
  112. </xsl:when>
  113. <xsl:otherwise>
  114. <xsl:apply-templates select="glossentry"/>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. </dl>
  118. </div>
  119. </xsl:template>
  120. <xsl:template match="glossdiv/title">
  121. <h3>
  122. <xsl:apply-templates select="." mode="common.html.attributes"/>
  123. <xsl:apply-templates/>
  124. </h3>
  125. </xsl:template>
  126. <!-- ==================================================================== -->
  127. <!--
  128. GlossEntry ::=
  129. GlossTerm, Acronym?, Abbrev?,
  130. (IndexTerm)*,
  131. RevHistory?,
  132. (GlossSee | GlossDef+)
  133. -->
  134. <xsl:template match="glossentry">
  135. <xsl:choose>
  136. <xsl:when test="$glossentry.show.acronym = 'primary'">
  137. <dt>
  138. <xsl:call-template name="id.attribute">
  139. <xsl:with-param name="conditional">
  140. <xsl:choose>
  141. <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
  142. <xsl:otherwise>1</xsl:otherwise>
  143. </xsl:choose>
  144. </xsl:with-param>
  145. </xsl:call-template>
  146. <xsl:call-template name="anchor">
  147. <xsl:with-param name="conditional">
  148. <xsl:choose>
  149. <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
  150. <xsl:otherwise>1</xsl:otherwise>
  151. </xsl:choose>
  152. </xsl:with-param>
  153. </xsl:call-template>
  154. <xsl:choose>
  155. <xsl:when test="acronym|abbrev">
  156. <xsl:apply-templates select="acronym|abbrev"/>
  157. <xsl:text> (</xsl:text>
  158. <xsl:apply-templates select="glossterm"/>
  159. <xsl:text>)</xsl:text>
  160. </xsl:when>
  161. <xsl:otherwise>
  162. <xsl:apply-templates select="glossterm"/>
  163. </xsl:otherwise>
  164. </xsl:choose>
  165. </dt>
  166. </xsl:when>
  167. <xsl:when test="$glossentry.show.acronym = 'yes'">
  168. <dt>
  169. <xsl:call-template name="id.attribute">
  170. <xsl:with-param name="conditional">
  171. <xsl:choose>
  172. <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
  173. <xsl:otherwise>1</xsl:otherwise>
  174. </xsl:choose>
  175. </xsl:with-param>
  176. </xsl:call-template>
  177. <xsl:call-template name="anchor">
  178. <xsl:with-param name="conditional">
  179. <xsl:choose>
  180. <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
  181. <xsl:otherwise>1</xsl:otherwise>
  182. </xsl:choose>
  183. </xsl:with-param>
  184. </xsl:call-template>
  185. <xsl:apply-templates select="glossterm"/>
  186. <xsl:if test="acronym|abbrev">
  187. <xsl:text> (</xsl:text>
  188. <xsl:apply-templates select="acronym|abbrev"/>
  189. <xsl:text>)</xsl:text>
  190. </xsl:if>
  191. </dt>
  192. </xsl:when>
  193. <xsl:otherwise>
  194. <dt>
  195. <xsl:call-template name="id.attribute">
  196. <xsl:with-param name="conditional">
  197. <xsl:choose>
  198. <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
  199. <xsl:otherwise>1</xsl:otherwise>
  200. </xsl:choose>
  201. </xsl:with-param>
  202. </xsl:call-template>
  203. <xsl:call-template name="anchor">
  204. <xsl:with-param name="conditional">
  205. <xsl:choose>
  206. <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
  207. <xsl:otherwise>1</xsl:otherwise>
  208. </xsl:choose>
  209. </xsl:with-param>
  210. </xsl:call-template>
  211. <xsl:apply-templates select="glossterm"/>
  212. </dt>
  213. </xsl:otherwise>
  214. </xsl:choose>
  215. <xsl:apply-templates select="indexterm|revhistory|glosssee|glossdef"/>
  216. </xsl:template>
  217. <xsl:template match="glossentry/glossterm">
  218. <span>
  219. <xsl:apply-templates select="." mode="common.html.attributes"/>
  220. <xsl:call-template name="id.attribute"/>
  221. <xsl:call-template name="anchor"/>
  222. <xsl:apply-templates/>
  223. </span>
  224. <xsl:if test="following-sibling::glossterm">, </xsl:if>
  225. </xsl:template>
  226. <xsl:template match="glossentry/acronym">
  227. <xsl:apply-templates/>
  228. <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
  229. </xsl:template>
  230. <xsl:template match="glossentry/abbrev">
  231. <xsl:apply-templates/>
  232. <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
  233. </xsl:template>
  234. <xsl:template match="glossentry/revhistory">
  235. </xsl:template>
  236. <xsl:template match="glossentry/glosssee">
  237. <xsl:variable name="otherterm" select="@otherterm"/>
  238. <xsl:variable name="targets" select="key('id', $otherterm)"/>
  239. <xsl:variable name="target" select="$targets[1]"/>
  240. <xsl:variable name="xlink" select="@xlink:href"/>
  241. <dd>
  242. <p>
  243. <xsl:variable name="template">
  244. <xsl:call-template name="gentext.template">
  245. <xsl:with-param name="context" select="'glossary'"/>
  246. <xsl:with-param name="name" select="'see'"/>
  247. </xsl:call-template>
  248. </xsl:variable>
  249. <xsl:variable name="title">
  250. <xsl:choose>
  251. <xsl:when test="$target">
  252. <a>
  253. <xsl:apply-templates select="." mode="common.html.attributes"/>
  254. <xsl:call-template name="id.attribute"/>
  255. <xsl:attribute name="href">
  256. <xsl:call-template name="href.target">
  257. <xsl:with-param name="object" select="$target"/>
  258. </xsl:call-template>
  259. </xsl:attribute>
  260. <xsl:apply-templates select="$target" mode="xref-to"/>
  261. </a>
  262. </xsl:when>
  263. <xsl:when test="$xlink">
  264. <xsl:call-template name="simple.xlink">
  265. <xsl:with-param name="content">
  266. <xsl:apply-templates/>
  267. </xsl:with-param>
  268. </xsl:call-template>
  269. </xsl:when>
  270. <xsl:when test="$otherterm != '' and not($target)">
  271. <xsl:message>
  272. <xsl:text>Warning: glosssee @otherterm reference not found: </xsl:text>
  273. <xsl:value-of select="$otherterm"/>
  274. </xsl:message>
  275. <xsl:apply-templates/>
  276. </xsl:when>
  277. <xsl:otherwise>
  278. <xsl:apply-templates/>
  279. </xsl:otherwise>
  280. </xsl:choose>
  281. </xsl:variable>
  282. <xsl:call-template name="substitute-markup">
  283. <xsl:with-param name="template" select="$template"/>
  284. <xsl:with-param name="title" select="$title"/>
  285. </xsl:call-template>
  286. </p>
  287. </dd>
  288. </xsl:template>
  289. <xsl:template match="glossentry/glossdef">
  290. <dd>
  291. <xsl:apply-templates select="." mode="common.html.attributes"/>
  292. <xsl:call-template name="id.attribute"/>
  293. <xsl:call-template name="anchor"/>
  294. <xsl:apply-templates select="*[local-name(.) != 'glossseealso']"/>
  295. <xsl:if test="glossseealso">
  296. <p>
  297. <xsl:variable name="template">
  298. <xsl:call-template name="gentext.template">
  299. <xsl:with-param name="context" select="'glossary'"/>
  300. <xsl:with-param name="name" select="'seealso'"/>
  301. </xsl:call-template>
  302. </xsl:variable>
  303. <xsl:variable name="title">
  304. <xsl:apply-templates select="glossseealso"/>
  305. </xsl:variable>
  306. <xsl:call-template name="substitute-markup">
  307. <xsl:with-param name="template" select="$template"/>
  308. <xsl:with-param name="title" select="$title"/>
  309. </xsl:call-template>
  310. </p>
  311. </xsl:if>
  312. </dd>
  313. </xsl:template>
  314. <xsl:template match="glossseealso">
  315. <xsl:variable name="otherterm" select="@otherterm"/>
  316. <xsl:variable name="targets" select="key('id', $otherterm)"/>
  317. <xsl:variable name="target" select="$targets[1]"/>
  318. <xsl:variable name="xlink" select="@xlink:href"/>
  319. <xsl:choose>
  320. <xsl:when test="$target">
  321. <a>
  322. <xsl:apply-templates select="." mode="common.html.attributes"/>
  323. <xsl:call-template name="id.attribute"/>
  324. <xsl:attribute name="href">
  325. <xsl:call-template name="href.target">
  326. <xsl:with-param name="object" select="$target"/>
  327. </xsl:call-template>
  328. </xsl:attribute>
  329. <xsl:apply-templates select="$target" mode="xref-to"/>
  330. </a>
  331. </xsl:when>
  332. <xsl:when test="$xlink">
  333. <xsl:call-template name="simple.xlink">
  334. <xsl:with-param name="content">
  335. <xsl:apply-templates/>
  336. </xsl:with-param>
  337. </xsl:call-template>
  338. </xsl:when>
  339. <xsl:when test="$otherterm != '' and not($target)">
  340. <xsl:message>
  341. <xsl:text>Warning: glossseealso @otherterm reference not found: </xsl:text>
  342. <xsl:value-of select="$otherterm"/>
  343. </xsl:message>
  344. <xsl:apply-templates/>
  345. </xsl:when>
  346. <xsl:otherwise>
  347. <xsl:apply-templates/>
  348. </xsl:otherwise>
  349. </xsl:choose>
  350. <xsl:choose>
  351. <xsl:when test="position() = last()"/>
  352. <xsl:otherwise>
  353. <xsl:call-template name="gentext.template">
  354. <xsl:with-param name="context" select="'glossary'"/>
  355. <xsl:with-param name="name" select="'seealso-separator'"/>
  356. </xsl:call-template>
  357. </xsl:otherwise>
  358. </xsl:choose>
  359. </xsl:template>
  360. <!-- ==================================================================== -->
  361. <!-- Glossary collection -->
  362. <xsl:template match="glossary[@role='auto']" priority="2">
  363. &setup-language-variable;
  364. <xsl:variable name="terms"
  365. select="//glossterm[not(parent::glossdef)]|//firstterm"/>
  366. <xsl:variable name="collection" select="document($glossary.collection, .)"/>
  367. <xsl:call-template name="id.warning"/>
  368. <xsl:if test="$glossary.collection = ''">
  369. <xsl:message>
  370. <xsl:text>Warning: processing automatic glossary </xsl:text>
  371. <xsl:text>without a glossary.collection file.</xsl:text>
  372. </xsl:message>
  373. </xsl:if>
  374. <xsl:if test="not($collection) and $glossary.collection != ''">
  375. <xsl:message>
  376. <xsl:text>Warning: processing automatic glossary but unable to </xsl:text>
  377. <xsl:text>open glossary.collection file '</xsl:text>
  378. <xsl:value-of select="$glossary.collection"/>
  379. <xsl:text>'</xsl:text>
  380. </xsl:message>
  381. </xsl:if>
  382. <div>
  383. <xsl:apply-templates select="." mode="common.html.attributes"/>
  384. <xsl:call-template name="id.attribute">
  385. <xsl:with-param name="conditional" select="0"/>
  386. </xsl:call-template>
  387. <xsl:call-template name="glossary.titlepage"/>
  388. <xsl:choose>
  389. <xsl:when test="glossdiv and $collection//glossdiv">
  390. <xsl:for-each select="$collection//glossdiv">
  391. <!-- first see if there are any in this div -->
  392. <xsl:variable name="exist.test">
  393. <xsl:for-each select="glossentry">
  394. <xsl:variable name="cterm" select="glossterm"/>
  395. <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  396. <xsl:value-of select="glossterm"/>
  397. </xsl:if>
  398. </xsl:for-each>
  399. </xsl:variable>
  400. <xsl:if test="$exist.test != ''">
  401. <xsl:apply-templates select="." mode="auto-glossary">
  402. <xsl:with-param name="terms" select="$terms"/>
  403. </xsl:apply-templates>
  404. </xsl:if>
  405. </xsl:for-each>
  406. </xsl:when>
  407. <xsl:otherwise>
  408. <dl>
  409. <xsl:choose>
  410. <xsl:when test="$glossary.sort != 0">
  411. <xsl:for-each select="$collection//glossentry">
  412. <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
  413. <xsl:variable name="cterm" select="glossterm"/>
  414. <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  415. <xsl:apply-templates select="." mode="auto-glossary"/>
  416. </xsl:if>
  417. </xsl:for-each>
  418. </xsl:when>
  419. <xsl:otherwise>
  420. <xsl:for-each select="$collection//glossentry">
  421. <xsl:variable name="cterm" select="glossterm"/>
  422. <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  423. <xsl:apply-templates select="." mode="auto-glossary"/>
  424. </xsl:if>
  425. </xsl:for-each>
  426. </xsl:otherwise>
  427. </xsl:choose>
  428. </dl>
  429. </xsl:otherwise>
  430. </xsl:choose>
  431. <xsl:if test="not(parent::article)">
  432. <xsl:call-template name="process.footnotes"/>
  433. </xsl:if>
  434. </div>
  435. </xsl:template>
  436. <xsl:template match="*" mode="auto-glossary">
  437. <!-- pop back out to the default mode for most elements -->
  438. <xsl:apply-templates select="."/>
  439. </xsl:template>
  440. <xsl:template match="glossdiv" mode="auto-glossary">
  441. <xsl:param name="terms" select="."/>
  442. &setup-language-variable;
  443. <div>
  444. <xsl:apply-templates select="." mode="common.html.attributes"/>
  445. <xsl:call-template name="id.attribute">
  446. <xsl:with-param name="conditional" select="0"/>
  447. </xsl:call-template>
  448. <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
  449. <dl>
  450. <xsl:choose>
  451. <xsl:when test="$glossary.sort != 0">
  452. <xsl:for-each select="glossentry">
  453. <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
  454. <xsl:variable name="cterm" select="glossterm"/>
  455. <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  456. <xsl:apply-templates select="." mode="auto-glossary"/>
  457. </xsl:if>
  458. </xsl:for-each>
  459. </xsl:when>
  460. <xsl:otherwise>
  461. <xsl:for-each select="glossentry">
  462. <xsl:variable name="cterm" select="glossterm"/>
  463. <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  464. <xsl:apply-templates select="." mode="auto-glossary"/>
  465. </xsl:if>
  466. </xsl:for-each>
  467. </xsl:otherwise>
  468. </xsl:choose>
  469. </dl>
  470. </div>
  471. </xsl:template>
  472. <!-- ==================================================================== -->
  473. </xsl:stylesheet>