autoidx.xsl 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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:exslt="http://exslt.org/common"
  8. extension-element-prefixes="exslt"
  9. exclude-result-prefixes="exslt"
  10. version="1.0">
  11. <!-- ********************************************************************
  12. $Id: autoidx.xsl 9707 2013-01-21 17:18:44Z bobstayton $
  13. ********************************************************************
  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.
  17. ******************************************************************** -->
  18. <!-- ==================================================================== -->
  19. <!-- The "basic" method derived from Jeni Tennison's work. -->
  20. <!-- The "kosek" method contributed by Jirka Kosek. -->
  21. <!-- The "kimber" method contributed by Eliot Kimber of Innodata Isogen. -->
  22. <xsl:variable name="kimber.imported" select="0"/>
  23. <xsl:variable name="kosek.imported" select="0"/>
  24. <xsl:key name="letter"
  25. match="indexterm"
  26. use="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  27. <xsl:key name="primary"
  28. match="indexterm"
  29. use="&primary;"/>
  30. <xsl:key name="secondary"
  31. match="indexterm"
  32. use="concat(&primary;, &sep;, &secondary;)"/>
  33. <xsl:key name="tertiary"
  34. match="indexterm"
  35. use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
  36. <xsl:key name="endofrange"
  37. match="indexterm[@class='endofrange']"
  38. use="@startref"/>
  39. <xsl:key name="primary-section"
  40. match="indexterm[not(secondary) and not(see)]"
  41. use="concat(&primary;, &sep;, &section.id;)"/>
  42. <xsl:key name="secondary-section"
  43. match="indexterm[not(tertiary) and not(see)]"
  44. use="concat(&primary;, &sep;, &secondary;, &sep;, &section.id;)"/>
  45. <xsl:key name="tertiary-section"
  46. match="indexterm[not(see)]"
  47. use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, &section.id;)"/>
  48. <xsl:key name="see-also"
  49. match="indexterm[seealso]"
  50. use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso)"/>
  51. <xsl:key name="see"
  52. match="indexterm[see]"
  53. use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see)"/>
  54. <xsl:key name="sections" match="*[@id or @xml:id]" use="@id|@xml:id"/>
  55. <xsl:template name="generate-index">
  56. <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
  57. <xsl:choose>
  58. <xsl:when test="$index.method = 'kosek'">
  59. <xsl:call-template name="generate-kosek-index">
  60. <xsl:with-param name="scope" select="$scope"/>
  61. </xsl:call-template>
  62. </xsl:when>
  63. <xsl:when test="$index.method = 'kimber'">
  64. <xsl:call-template name="generate-kimber-index">
  65. <xsl:with-param name="scope" select="$scope"/>
  66. </xsl:call-template>
  67. </xsl:when>
  68. <xsl:otherwise>
  69. <xsl:call-template name="generate-basic-index">
  70. <xsl:with-param name="scope" select="$scope"/>
  71. </xsl:call-template>
  72. </xsl:otherwise>
  73. </xsl:choose>
  74. </xsl:template>
  75. <xsl:template name="generate-basic-index">
  76. <xsl:param name="scope" select="NOTANODE"/>
  77. <xsl:variable name="role">
  78. <xsl:if test="$index.on.role != 0">
  79. <xsl:value-of select="@role"/>
  80. </xsl:if>
  81. </xsl:variable>
  82. <xsl:variable name="type">
  83. <xsl:if test="$index.on.type != 0">
  84. <xsl:value-of select="@type"/>
  85. </xsl:if>
  86. </xsl:variable>
  87. <xsl:variable name="terms"
  88. select="//indexterm
  89. [count(.|key('letter',
  90. translate(substring(&primary;, 1, 1),
  91. &lowercase;,
  92. &uppercase;))
  93. [&scope;][1]) = 1
  94. and not(@class = 'endofrange')]"/>
  95. <xsl:variable name="alphabetical"
  96. select="$terms[contains(concat(&lowercase;, &uppercase;),
  97. substring(&primary;, 1, 1))]"/>
  98. <xsl:variable name="others" select="$terms[not(contains(concat(&lowercase;,
  99. &uppercase;),
  100. substring(&primary;, 1, 1)))]"/>
  101. <div class="index">
  102. <xsl:if test="$others">
  103. <xsl:choose>
  104. <xsl:when test="normalize-space($type) != '' and
  105. $others[@type = $type][count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  106. <div class="indexdiv">
  107. <h3>
  108. <xsl:call-template name="gentext">
  109. <xsl:with-param name="key" select="'index symbols'"/>
  110. </xsl:call-template>
  111. </h3>
  112. <dl>
  113. <xsl:apply-templates select="$others[count(.|key('primary', &primary;)[&scope;][1]) = 1]"
  114. mode="index-symbol-div">
  115. <xsl:with-param name="position" select="position()"/>
  116. <xsl:with-param name="scope" select="$scope"/>
  117. <xsl:with-param name="role" select="$role"/>
  118. <xsl:with-param name="type" select="$type"/>
  119. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  120. </xsl:apply-templates>
  121. </dl>
  122. </div>
  123. </xsl:when>
  124. <xsl:when test="normalize-space($type) != ''">
  125. <!-- Output nothing, as there isn't a match for $other using this $type -->
  126. </xsl:when>
  127. <xsl:otherwise>
  128. <div class="indexdiv">
  129. <h3>
  130. <xsl:call-template name="gentext">
  131. <xsl:with-param name="key" select="'index symbols'"/>
  132. </xsl:call-template>
  133. </h3>
  134. <dl>
  135. <xsl:apply-templates select="$others[count(.|key('primary',
  136. &primary;)[&scope;][1]) = 1]"
  137. mode="index-symbol-div">
  138. <xsl:with-param name="position" select="position()"/>
  139. <xsl:with-param name="scope" select="$scope"/>
  140. <xsl:with-param name="role" select="$role"/>
  141. <xsl:with-param name="type" select="$type"/>
  142. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  143. </xsl:apply-templates>
  144. </dl>
  145. </div>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. </xsl:if>
  149. <xsl:apply-templates select="$alphabetical[count(.|key('letter',
  150. translate(substring(&primary;, 1, 1),
  151. &lowercase;,&uppercase;))[&scope;][1]) = 1]"
  152. mode="index-div-basic">
  153. <xsl:with-param name="position" select="position()"/>
  154. <xsl:with-param name="scope" select="$scope"/>
  155. <xsl:with-param name="role" select="$role"/>
  156. <xsl:with-param name="type" select="$type"/>
  157. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  158. </xsl:apply-templates>
  159. </div>
  160. </xsl:template>
  161. <!-- This template not used if html/autoidx-kosek.xsl is imported -->
  162. <xsl:template name="generate-kosek-index">
  163. <xsl:param name="scope" select="NOTANODE"/>
  164. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  165. <xsl:if test="contains($vendor, 'libxslt')">
  166. <xsl:message terminate="yes">
  167. <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
  168. <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
  169. </xsl:message>
  170. </xsl:if>
  171. <xsl:if test="$exsl.node.set.available = 0">
  172. <xsl:message terminate="yes">
  173. <xsl:text>ERROR: the 'kosek' index method requires the </xsl:text>
  174. <xsl:text>exslt:node-set() function. Use a processor that </xsl:text>
  175. <xsl:text>has it, or use a different index method.</xsl:text>
  176. </xsl:message>
  177. </xsl:if>
  178. <xsl:if test="$kosek.imported = 0">
  179. <xsl:message terminate="yes">
  180. <xsl:text>ERROR: the 'kosek' index method requires the&#xA;</xsl:text>
  181. <xsl:text>kosek index extensions be imported:&#xA;</xsl:text>
  182. <xsl:text> xsl:import href="html/autoidx-kosek.xsl"</xsl:text>
  183. </xsl:message>
  184. </xsl:if>
  185. </xsl:template>
  186. <!-- This template not used if html/autoidx-kimber.xsl is imported -->
  187. <xsl:template name="generate-kimber-index">
  188. <xsl:param name="scope" select="NOTANODE"/>
  189. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  190. <xsl:if test="not(contains($vendor, 'SAXON '))">
  191. <xsl:message terminate="yes">
  192. <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
  193. <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
  194. </xsl:message>
  195. </xsl:if>
  196. <xsl:if test="$kimber.imported = 0">
  197. <xsl:message terminate="yes">
  198. <xsl:text>ERROR: the 'kimber' index method requires the&#xA;</xsl:text>
  199. <xsl:text>kimber index extensions be imported:&#xA;</xsl:text>
  200. <xsl:text> xsl:import href="html/autoidx-kimber.xsl"</xsl:text>
  201. </xsl:message>
  202. </xsl:if>
  203. </xsl:template>
  204. <xsl:template match="indexterm" mode="index-div-basic">
  205. <xsl:param name="scope" select="."/>
  206. <xsl:param name="role" select="''"/>
  207. <xsl:param name="type" select="''"/>
  208. <xsl:variable name="key"
  209. select="translate(substring(&primary;, 1, 1),
  210. &lowercase;,&uppercase;)"/>
  211. <xsl:if test="key('letter', $key)[&scope;]
  212. [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  213. <div class="indexdiv">
  214. <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
  215. <h3>
  216. <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
  217. </h3>
  218. </xsl:if>
  219. <dl>
  220. <xsl:apply-templates select="key('letter', $key)[&scope;]
  221. [count(.|key('primary', &primary;)
  222. [&scope;][1])=1]"
  223. mode="index-primary">
  224. <xsl:with-param name="position" select="position()"/>
  225. <xsl:with-param name="scope" select="$scope"/>
  226. <xsl:with-param name="role" select="$role"/>
  227. <xsl:with-param name="type" select="$type"/>
  228. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  229. </xsl:apply-templates>
  230. </dl>
  231. </div>
  232. </xsl:if>
  233. </xsl:template>
  234. <xsl:template match="indexterm" mode="index-symbol-div">
  235. <xsl:param name="scope" select="/"/>
  236. <xsl:param name="role" select="''"/>
  237. <xsl:param name="type" select="''"/>
  238. <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),
  239. &lowercase;,&uppercase;)"/>
  240. <xsl:apply-templates select="key('letter', $key)
  241. [&scope;][count(.|key('primary', &primary;)[1]) = 1]"
  242. mode="index-primary">
  243. <xsl:with-param name="position" select="position()"/>
  244. <xsl:with-param name="scope" select="$scope"/>
  245. <xsl:with-param name="role" select="$role"/>
  246. <xsl:with-param name="type" select="$type"/>
  247. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  248. </xsl:apply-templates>
  249. </xsl:template>
  250. <xsl:template match="indexterm" mode="index-primary">
  251. <xsl:param name="scope" select="."/>
  252. <xsl:param name="role" select="''"/>
  253. <xsl:param name="type" select="''"/>
  254. <xsl:variable name="key" select="&primary;"/>
  255. <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
  256. <dt>
  257. <xsl:for-each select="$refs/primary">
  258. <xsl:if test="@id or @xml:id">
  259. <xsl:choose>
  260. <xsl:when test="$generate.id.attributes = 0">
  261. <a name="{(@id|@xml:id)[1]}"/>
  262. </xsl:when>
  263. <xsl:otherwise>
  264. <span>
  265. <xsl:call-template name="id.attribute"/>
  266. </span>
  267. </xsl:otherwise>
  268. </xsl:choose>
  269. </xsl:if>
  270. </xsl:for-each>
  271. <xsl:value-of select="primary"/>
  272. <xsl:choose>
  273. <xsl:when test="$index.links.to.section = 1">
  274. <xsl:for-each select="$refs[@zone != '' or generate-id() = generate-id(key('primary-section', concat($key, &sep;, &section.id;))[&scope;][1])]">
  275. <xsl:apply-templates select="." mode="reference">
  276. <xsl:with-param name="position" select="position()"/>
  277. <xsl:with-param name="scope" select="$scope"/>
  278. <xsl:with-param name="role" select="$role"/>
  279. <xsl:with-param name="type" select="$type"/>
  280. </xsl:apply-templates>
  281. </xsl:for-each>
  282. </xsl:when>
  283. <xsl:otherwise>
  284. <xsl:for-each select="$refs[not(see)
  285. and not(secondary)][&scope;]">
  286. <xsl:apply-templates select="." mode="reference">
  287. <xsl:with-param name="position" select="position()"/>
  288. <xsl:with-param name="scope" select="$scope"/>
  289. <xsl:with-param name="role" select="$role"/>
  290. <xsl:with-param name="type" select="$type"/>
  291. </xsl:apply-templates>
  292. </xsl:for-each>
  293. </xsl:otherwise>
  294. </xsl:choose>
  295. <xsl:if test="$refs[not(secondary)]/*[self::see]">
  296. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[&scope;][1])]"
  297. mode="index-see">
  298. <xsl:with-param name="position" select="position()"/>
  299. <xsl:with-param name="scope" select="$scope"/>
  300. <xsl:with-param name="role" select="$role"/>
  301. <xsl:with-param name="type" select="$type"/>
  302. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  303. </xsl:apply-templates>
  304. </xsl:if>
  305. </dt>
  306. <xsl:choose>
  307. <xsl:when test="$refs/secondary or $refs[not(secondary)]/*[self::seealso]">
  308. <dd>
  309. <dl>
  310. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[&scope;][1])]"
  311. mode="index-seealso">
  312. <xsl:with-param name="position" select="position()"/>
  313. <xsl:with-param name="scope" select="$scope"/>
  314. <xsl:with-param name="role" select="$role"/>
  315. <xsl:with-param name="type" select="$type"/>
  316. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  317. </xsl:apply-templates>
  318. <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[&scope;][1]) = 1]"
  319. mode="index-secondary">
  320. <xsl:with-param name="position" select="position()"/>
  321. <xsl:with-param name="scope" select="$scope"/>
  322. <xsl:with-param name="role" select="$role"/>
  323. <xsl:with-param name="type" select="$type"/>
  324. <xsl:sort select="translate(&secondary;, &lowercase;, &uppercase;)"/>
  325. </xsl:apply-templates>
  326. </dl>
  327. </dd>
  328. </xsl:when>
  329. <!-- HTML5 requires dd for each dt -->
  330. <xsl:when test="$div.element = 'section'">
  331. <dd></dd>
  332. </xsl:when>
  333. </xsl:choose>
  334. </xsl:template>
  335. <xsl:template match="indexterm" mode="index-secondary">
  336. <xsl:param name="scope" select="."/>
  337. <xsl:param name="role" select="''"/>
  338. <xsl:param name="type" select="''"/>
  339. <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
  340. <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
  341. <dt>
  342. <xsl:for-each select="$refs/secondary">
  343. <xsl:if test="@id or @xml:id">
  344. <xsl:choose>
  345. <xsl:when test="$generate.id.attributes = 0">
  346. <a name="{(@id|@xml:id)[1]}"/>
  347. </xsl:when>
  348. <xsl:otherwise>
  349. <span>
  350. <xsl:call-template name="id.attribute"/>
  351. </span>
  352. </xsl:otherwise>
  353. </xsl:choose>
  354. </xsl:if>
  355. </xsl:for-each>
  356. <xsl:value-of select="secondary"/>
  357. <xsl:choose>
  358. <xsl:when test="$index.links.to.section = 1">
  359. <xsl:for-each select="$refs[@zone != '' or generate-id() = generate-id(key('secondary-section', concat($key, &sep;, &section.id;))[&scope;][1])]">
  360. <xsl:apply-templates select="." mode="reference">
  361. <xsl:with-param name="position" select="position()"/>
  362. <xsl:with-param name="scope" select="$scope"/>
  363. <xsl:with-param name="role" select="$role"/>
  364. <xsl:with-param name="type" select="$type"/>
  365. </xsl:apply-templates>
  366. </xsl:for-each>
  367. </xsl:when>
  368. <xsl:otherwise>
  369. <xsl:for-each select="$refs[not(see)
  370. and not(tertiary)][&scope;]">
  371. <xsl:apply-templates select="." mode="reference">
  372. <xsl:with-param name="position" select="position()"/>
  373. <xsl:with-param name="scope" select="$scope"/>
  374. <xsl:with-param name="role" select="$role"/>
  375. <xsl:with-param name="type" select="$type"/>
  376. </xsl:apply-templates>
  377. </xsl:for-each>
  378. </xsl:otherwise>
  379. </xsl:choose>
  380. <xsl:if test="$refs[not(tertiary)]/*[self::see]">
  381. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[&scope;][1])]"
  382. mode="index-see">
  383. <xsl:with-param name="position" select="position()"/>
  384. <xsl:with-param name="scope" select="$scope"/>
  385. <xsl:with-param name="role" select="$role"/>
  386. <xsl:with-param name="type" select="$type"/>
  387. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  388. </xsl:apply-templates>
  389. </xsl:if>
  390. </dt>
  391. <xsl:choose>
  392. <xsl:when test="$refs/tertiary or $refs[not(tertiary)]/*[self::seealso]">
  393. <dd>
  394. <dl>
  395. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[&scope;][1])]"
  396. mode="index-seealso">
  397. <xsl:with-param name="position" select="position()"/>
  398. <xsl:with-param name="scope" select="$scope"/>
  399. <xsl:with-param name="role" select="$role"/>
  400. <xsl:with-param name="type" select="$type"/>
  401. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  402. </xsl:apply-templates>
  403. <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[&scope;][1]) = 1]"
  404. mode="index-tertiary">
  405. <xsl:with-param name="position" select="position()"/>
  406. <xsl:with-param name="scope" select="$scope"/>
  407. <xsl:with-param name="role" select="$role"/>
  408. <xsl:with-param name="type" select="$type"/>
  409. <xsl:sort select="translate(&tertiary;, &lowercase;, &uppercase;)"/>
  410. </xsl:apply-templates>
  411. </dl>
  412. </dd>
  413. </xsl:when>
  414. <!-- HTML5 requires dd for each dt -->
  415. <xsl:when test="$div.element = 'section'">
  416. <dd></dd>
  417. </xsl:when>
  418. </xsl:choose>
  419. </xsl:template>
  420. <xsl:template match="indexterm" mode="index-tertiary">
  421. <xsl:param name="scope" select="."/>
  422. <xsl:param name="role" select="''"/>
  423. <xsl:param name="type" select="''"/>
  424. <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
  425. <xsl:variable name="refs" select="key('tertiary', $key)[&scope;]"/>
  426. <dt>
  427. <xsl:for-each select="$refs/tertiary">
  428. <xsl:if test="@id or @xml:id">
  429. <xsl:choose>
  430. <xsl:when test="$generate.id.attributes = 0">
  431. <a name="{(@id|@xml:id)[1]}"/>
  432. </xsl:when>
  433. <xsl:otherwise>
  434. <span>
  435. <xsl:call-template name="id.attribute"/>
  436. </span>
  437. </xsl:otherwise>
  438. </xsl:choose>
  439. </xsl:if>
  440. </xsl:for-each>
  441. <xsl:value-of select="tertiary"/>
  442. <xsl:choose>
  443. <xsl:when test="$index.links.to.section = 1">
  444. <xsl:for-each select="$refs[@zone != '' or generate-id() = generate-id(key('tertiary-section', concat($key, &sep;, &section.id;))[&scope;][1])]">
  445. <xsl:apply-templates select="." mode="reference">
  446. <xsl:with-param name="position" select="position()"/>
  447. <xsl:with-param name="scope" select="$scope"/>
  448. <xsl:with-param name="role" select="$role"/>
  449. <xsl:with-param name="type" select="$type"/>
  450. </xsl:apply-templates>
  451. </xsl:for-each>
  452. </xsl:when>
  453. <xsl:otherwise>
  454. <xsl:for-each select="$refs[not(see)][&scope;]">
  455. <xsl:apply-templates select="." mode="reference">
  456. <xsl:with-param name="position" select="position()"/>
  457. <xsl:with-param name="scope" select="$scope"/>
  458. <xsl:with-param name="role" select="$role"/>
  459. <xsl:with-param name="type" select="$type"/>
  460. </xsl:apply-templates>
  461. </xsl:for-each>
  462. </xsl:otherwise>
  463. </xsl:choose>
  464. <xsl:if test="$refs/see">
  465. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[&scope;][1])]"
  466. mode="index-see">
  467. <xsl:with-param name="position" select="position()"/>
  468. <xsl:with-param name="scope" select="$scope"/>
  469. <xsl:with-param name="role" select="$role"/>
  470. <xsl:with-param name="type" select="$type"/>
  471. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  472. </xsl:apply-templates>
  473. </xsl:if>
  474. </dt>
  475. <xsl:choose>
  476. <xsl:when test="$refs/seealso">
  477. <dd>
  478. <dl>
  479. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[&scope;][1])]"
  480. mode="index-seealso">
  481. <xsl:with-param name="position" select="position()"/>
  482. <xsl:with-param name="scope" select="$scope"/>
  483. <xsl:with-param name="role" select="$role"/>
  484. <xsl:with-param name="type" select="$type"/>
  485. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  486. </xsl:apply-templates>
  487. </dl>
  488. </dd>
  489. </xsl:when>
  490. <!-- HTML5 requires dd for each dt -->
  491. <xsl:when test="$div.element = 'section'">
  492. <dd></dd>
  493. </xsl:when>
  494. </xsl:choose>
  495. </xsl:template>
  496. <xsl:template match="indexterm" mode="reference">
  497. <xsl:param name="scope" select="."/>
  498. <xsl:param name="role" select="''"/>
  499. <xsl:param name="type" select="''"/>
  500. <xsl:param name="position"/>
  501. <xsl:param name="separator" select="''"/>
  502. <xsl:variable name="term.separator">
  503. <xsl:call-template name="index.separator">
  504. <xsl:with-param name="key" select="'index.term.separator'"/>
  505. </xsl:call-template>
  506. </xsl:variable>
  507. <xsl:variable name="number.separator">
  508. <xsl:call-template name="index.separator">
  509. <xsl:with-param name="key" select="'index.number.separator'"/>
  510. </xsl:call-template>
  511. </xsl:variable>
  512. <xsl:variable name="range.separator">
  513. <xsl:call-template name="index.separator">
  514. <xsl:with-param name="key" select="'index.range.separator'"/>
  515. </xsl:call-template>
  516. </xsl:variable>
  517. <xsl:choose>
  518. <xsl:when test="$separator != ''">
  519. <xsl:value-of select="$separator"/>
  520. </xsl:when>
  521. <xsl:when test="$position = 1">
  522. <xsl:value-of select="$term.separator"/>
  523. </xsl:when>
  524. <xsl:otherwise>
  525. <xsl:value-of select="$number.separator"/>
  526. </xsl:otherwise>
  527. </xsl:choose>
  528. <xsl:choose>
  529. <xsl:when test="@zone and string(@zone)">
  530. <xsl:call-template name="reference">
  531. <xsl:with-param name="zones" select="normalize-space(@zone)"/>
  532. <xsl:with-param name="position" select="position()"/>
  533. <xsl:with-param name="scope" select="$scope"/>
  534. <xsl:with-param name="role" select="$role"/>
  535. <xsl:with-param name="type" select="$type"/>
  536. </xsl:call-template>
  537. </xsl:when>
  538. <xsl:otherwise>
  539. <a>
  540. <xsl:apply-templates select="." mode="class.attribute"/>
  541. <xsl:variable name="title">
  542. <xsl:choose>
  543. <xsl:when test="$index.prefer.titleabbrev != 0">
  544. <xsl:apply-templates select="&section;" mode="titleabbrev.markup"/>
  545. </xsl:when>
  546. <xsl:otherwise>
  547. <xsl:apply-templates select="&section;" mode="title.markup"/>
  548. </xsl:otherwise>
  549. </xsl:choose>
  550. </xsl:variable>
  551. <xsl:attribute name="href">
  552. <xsl:choose>
  553. <xsl:when test="$index.links.to.section = 1">
  554. <xsl:call-template name="href.target">
  555. <xsl:with-param name="object" select="&section;"/>
  556. <xsl:with-param name="context"
  557. select="(//index[&scope;] | //setindex[&scope;])[1]"/>
  558. </xsl:call-template>
  559. </xsl:when>
  560. <xsl:otherwise>
  561. <xsl:call-template name="href.target">
  562. <xsl:with-param name="object" select="."/>
  563. <xsl:with-param name="context"
  564. select="(//index[&scope;] | //setindex[&scope;])[1]"/>
  565. </xsl:call-template>
  566. </xsl:otherwise>
  567. </xsl:choose>
  568. </xsl:attribute>
  569. <xsl:value-of select="$title"/> <!-- text only -->
  570. </a>
  571. <xsl:variable name="id" select="(@id|@xml:id)[1]"/>
  572. <xsl:if test="key('endofrange', $id)[&scope;]">
  573. <xsl:apply-templates select="key('endofrange', $id)[&scope;][last()]"
  574. mode="reference">
  575. <xsl:with-param name="position" select="position()"/>
  576. <xsl:with-param name="scope" select="$scope"/>
  577. <xsl:with-param name="role" select="$role"/>
  578. <xsl:with-param name="type" select="$type"/>
  579. <xsl:with-param name="separator" select="$range.separator"/>
  580. </xsl:apply-templates>
  581. </xsl:if>
  582. </xsl:otherwise>
  583. </xsl:choose>
  584. </xsl:template>
  585. <xsl:template name="reference">
  586. <xsl:param name="scope" select="."/>
  587. <xsl:param name="role" select="''"/>
  588. <xsl:param name="type" select="''"/>
  589. <xsl:param name="zones"/>
  590. <xsl:choose>
  591. <xsl:when test="contains($zones, ' ')">
  592. <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
  593. <xsl:variable name="target" select="key('sections', $zone)"/>
  594. <a>
  595. <xsl:apply-templates select="." mode="class.attribute"/>
  596. <xsl:call-template name="id.attribute"/>
  597. <xsl:attribute name="href">
  598. <xsl:call-template name="href.target">
  599. <xsl:with-param name="object" select="$target[1]"/>
  600. <xsl:with-param name="context" select="//index[&scope;][1]"/>
  601. </xsl:call-template>
  602. </xsl:attribute>
  603. <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
  604. </a>
  605. <xsl:text>, </xsl:text>
  606. <xsl:call-template name="reference">
  607. <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
  608. <xsl:with-param name="position" select="position()"/>
  609. <xsl:with-param name="scope" select="$scope"/>
  610. <xsl:with-param name="role" select="$role"/>
  611. <xsl:with-param name="type" select="$type"/>
  612. </xsl:call-template>
  613. </xsl:when>
  614. <xsl:otherwise>
  615. <xsl:variable name="zone" select="$zones"/>
  616. <xsl:variable name="target" select="key('sections', $zone)"/>
  617. <a>
  618. <xsl:apply-templates select="." mode="class.attribute"/>
  619. <xsl:call-template name="id.attribute"/>
  620. <xsl:attribute name="href">
  621. <xsl:call-template name="href.target">
  622. <xsl:with-param name="object" select="$target[1]"/>
  623. <xsl:with-param name="context" select="//index[&scope;][1]"/>
  624. </xsl:call-template>
  625. </xsl:attribute>
  626. <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
  627. </a>
  628. </xsl:otherwise>
  629. </xsl:choose>
  630. </xsl:template>
  631. <xsl:template match="indexterm" mode="index-see">
  632. <xsl:param name="scope" select="."/>
  633. <xsl:param name="role" select="''"/>
  634. <xsl:param name="type" select="''"/>
  635. <xsl:text> (</xsl:text>
  636. <xsl:call-template name="gentext">
  637. <xsl:with-param name="key" select="'see'"/>
  638. </xsl:call-template>
  639. <xsl:text> </xsl:text>
  640. <xsl:value-of select="see"/>
  641. <xsl:text>)</xsl:text>
  642. </xsl:template>
  643. <xsl:template match="indexterm" mode="index-seealso">
  644. <xsl:param name="scope" select="."/>
  645. <xsl:param name="role" select="''"/>
  646. <xsl:param name="type" select="''"/>
  647. <xsl:for-each select="seealso">
  648. <xsl:sort select="translate(., &lowercase;, &uppercase;)"/>
  649. <dt>
  650. <xsl:text>(</xsl:text>
  651. <xsl:call-template name="gentext">
  652. <xsl:with-param name="key" select="'seealso'"/>
  653. </xsl:call-template>
  654. <xsl:text> </xsl:text>
  655. <xsl:value-of select="."/>
  656. <xsl:text>)</xsl:text>
  657. </dt>
  658. <xsl:if test="$div.element = 'section'">
  659. <dd></dd>
  660. </xsl:if>
  661. </xsl:for-each>
  662. </xsl:template>
  663. <xsl:template match="*" mode="index-title-content">
  664. <xsl:variable name="title">
  665. <xsl:apply-templates select="&section;" mode="title.markup"/>
  666. </xsl:variable>
  667. <xsl:value-of select="$title"/>
  668. </xsl:template>
  669. <xsl:template name="index.separator">
  670. <xsl:param name="key" select="''"/>
  671. <xsl:param name="lang">
  672. <xsl:call-template name="l10n.language"/>
  673. </xsl:param>
  674. <xsl:choose>
  675. <xsl:when test="$key = 'index.term.separator'">
  676. <xsl:choose>
  677. <!-- Use the override if not blank -->
  678. <xsl:when test="$index.term.separator != ''">
  679. <xsl:copy-of select="$index.term.separator"/>
  680. </xsl:when>
  681. <xsl:otherwise>
  682. <xsl:call-template name="gentext.template">
  683. <xsl:with-param name="lang" select="$lang"/>
  684. <xsl:with-param name="context">index</xsl:with-param>
  685. <xsl:with-param name="name">term-separator</xsl:with-param>
  686. </xsl:call-template>
  687. </xsl:otherwise>
  688. </xsl:choose>
  689. </xsl:when>
  690. <xsl:when test="$key = 'index.number.separator'">
  691. <xsl:choose>
  692. <!-- Use the override if not blank -->
  693. <xsl:when test="$index.number.separator != ''">
  694. <xsl:copy-of select="$index.number.separator"/>
  695. </xsl:when>
  696. <xsl:otherwise>
  697. <xsl:call-template name="gentext.template">
  698. <xsl:with-param name="lang" select="$lang"/>
  699. <xsl:with-param name="context">index</xsl:with-param>
  700. <xsl:with-param name="name">number-separator</xsl:with-param>
  701. </xsl:call-template>
  702. </xsl:otherwise>
  703. </xsl:choose>
  704. </xsl:when>
  705. <xsl:when test="$key = 'index.range.separator'">
  706. <xsl:choose>
  707. <!-- Use the override if not blank -->
  708. <xsl:when test="$index.range.separator != ''">
  709. <xsl:copy-of select="$index.range.separator"/>
  710. </xsl:when>
  711. <xsl:otherwise>
  712. <xsl:call-template name="gentext.template">
  713. <xsl:with-param name="lang" select="$lang"/>
  714. <xsl:with-param name="context">index</xsl:with-param>
  715. <xsl:with-param name="name">range-separator</xsl:with-param>
  716. </xsl:call-template>
  717. </xsl:otherwise>
  718. </xsl:choose>
  719. </xsl:when>
  720. </xsl:choose>
  721. </xsl:template>
  722. </xsl:stylesheet>