autoidx.xsl 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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:fo="http://www.w3.org/1999/XSL/Format"
  8. xmlns:rx="http://www.renderx.com/XSL/Extensions"
  9. xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
  10. xmlns:exslt="http://exslt.org/common"
  11. extension-element-prefixes="exslt"
  12. exclude-result-prefixes="exslt"
  13. version="1.0">
  14. <!-- ********************************************************************
  15. $Id: autoidx.xsl 9647 2012-10-26 17:42:03Z bobstayton $
  16. ********************************************************************
  17. This file is part of the DocBook XSL Stylesheet distribution.
  18. See ../README or http://docbook.sf.net/ for copyright
  19. copyright and other information.
  20. ******************************************************************** -->
  21. <!-- ==================================================================== -->
  22. <!-- The "basic" method derived from Jeni Tennison's work. -->
  23. <!-- The "kosek" method contributed by Jirka Kosek. -->
  24. <!-- The "kimber" method contributed by Eliot Kimber of Innodata Isogen. -->
  25. <!-- Importing module for kimber or kosek method overrides one of these -->
  26. <xsl:param name="kimber.imported" select="0"/>
  27. <xsl:param name="kosek.imported" select="0"/>
  28. <!-- These keys used primary in all methods -->
  29. <xsl:key name="letter"
  30. match="indexterm"
  31. use="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  32. <xsl:key name="primary"
  33. match="indexterm"
  34. use="&primary;"/>
  35. <xsl:key name="secondary"
  36. match="indexterm"
  37. use="concat(&primary;, &sep;, &secondary;)"/>
  38. <xsl:key name="tertiary"
  39. match="indexterm"
  40. use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
  41. <xsl:key name="endofrange"
  42. match="indexterm[@class='endofrange']"
  43. use="@startref"/>
  44. <xsl:key name="see-also"
  45. match="indexterm[seealso]"
  46. use="concat(&primary;, &sep;,
  47. &secondary;, &sep;,
  48. &tertiary;, &sep;, seealso)"/>
  49. <xsl:key name="see"
  50. match="indexterm[see]"
  51. use="concat(&primary;, &sep;,
  52. &secondary;, &sep;,
  53. &tertiary;, &sep;, see)"/>
  54. <xsl:template name="generate-index">
  55. <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
  56. <xsl:choose>
  57. <xsl:when test="$index.method = 'kosek'">
  58. <xsl:call-template name="generate-kosek-index">
  59. <xsl:with-param name="scope" select="$scope"/>
  60. </xsl:call-template>
  61. </xsl:when>
  62. <xsl:when test="$index.method = 'kimber'">
  63. <xsl:call-template name="generate-kimber-index">
  64. <xsl:with-param name="scope" select="$scope"/>
  65. </xsl:call-template>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <xsl:call-template name="generate-basic-index">
  69. <xsl:with-param name="scope" select="$scope"/>
  70. </xsl:call-template>
  71. </xsl:otherwise>
  72. </xsl:choose>
  73. </xsl:template>
  74. <xsl:template name="generate-basic-index">
  75. <xsl:param name="scope" select="NOTANODE"/>
  76. <xsl:variable name="role">
  77. <xsl:if test="$index.on.role != 0">
  78. <xsl:value-of select="@role"/>
  79. </xsl:if>
  80. </xsl:variable>
  81. <xsl:variable name="type">
  82. <xsl:if test="$index.on.type != 0">
  83. <xsl:value-of select="@type"/>
  84. </xsl:if>
  85. </xsl:variable>
  86. <xsl:variable name="terms"
  87. select="//indexterm
  88. [count(.|key('letter',
  89. translate(substring(&primary;, 1, 1),
  90. &lowercase;,
  91. &uppercase;))
  92. [&scope;][1]) = 1
  93. and not(@class = 'endofrange')]"/>
  94. <xsl:variable name="alphabetical"
  95. select="$terms[contains(concat(&lowercase;, &uppercase;),
  96. substring(&primary;, 1, 1))]"/>
  97. <xsl:variable name="others" select="$terms[not(contains(
  98. concat(&lowercase;,
  99. &uppercase;),
  100. substring(&primary;, 1, 1)))]"/>
  101. <fo:block>
  102. <xsl:if test="$others">
  103. <xsl:call-template name="indexdiv.title">
  104. <xsl:with-param name="titlecontent">
  105. <xsl:call-template name="gentext">
  106. <xsl:with-param name="key" select="'index symbols'"/>
  107. </xsl:call-template>
  108. </xsl:with-param>
  109. </xsl:call-template>
  110. <fo:block>
  111. <xsl:apply-templates select="$others[count(.|key('primary',
  112. &primary;)[&scope;][1]) = 1]"
  113. mode="index-symbol-div">
  114. <xsl:with-param name="scope" select="$scope"/>
  115. <xsl:with-param name="role" select="$role"/>
  116. <xsl:with-param name="type" select="$type"/>
  117. <xsl:sort select="translate(&primary;, &lowercase;,
  118. &uppercase;)"/>
  119. </xsl:apply-templates>
  120. </fo:block>
  121. </xsl:if>
  122. <xsl:apply-templates select="$alphabetical[count(.|key('letter',
  123. translate(substring(&primary;, 1, 1),
  124. &lowercase;,&uppercase;))
  125. [&scope;][1]) = 1]"
  126. mode="index-div-basic">
  127. <xsl:with-param name="scope" select="$scope"/>
  128. <xsl:with-param name="role" select="$role"/>
  129. <xsl:with-param name="type" select="$type"/>
  130. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  131. </xsl:apply-templates>
  132. </fo:block>
  133. </xsl:template>
  134. <!-- This template not used if fo/autoidx-kosek.xsl is imported -->
  135. <xsl:template name="generate-kosek-index">
  136. <xsl:param name="scope" select="NOTANODE"/>
  137. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  138. <xsl:if test="contains($vendor, 'libxslt')">
  139. <xsl:message terminate="yes">
  140. <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
  141. <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
  142. </xsl:message>
  143. </xsl:if>
  144. <xsl:if test="$exsl.node.set.available = 0">
  145. <xsl:message terminate="yes">
  146. <xsl:text>ERROR: the 'kosek' index method requires the </xsl:text>
  147. <xsl:text>exslt:node-set() function. Use a processor that </xsl:text>
  148. <xsl:text>has it, or use a different index method.</xsl:text>
  149. </xsl:message>
  150. </xsl:if>
  151. <xsl:if test="$kosek.imported = 0">
  152. <xsl:message terminate="yes">
  153. <xsl:text>ERROR: the 'kosek' index method requires the&#xA;</xsl:text>
  154. <xsl:text>kosek index extensions be imported:&#xA;</xsl:text>
  155. <xsl:text> xsl:import href="fo/autoidx-kosek.xsl"</xsl:text>
  156. </xsl:message>
  157. </xsl:if>
  158. </xsl:template>
  159. <!-- This template not used if fo/autoidx-kimber.xsl is imported -->
  160. <xsl:template name="generate-kimber-index">
  161. <xsl:param name="scope" select="NOTANODE"/>
  162. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  163. <xsl:if test="not(contains($vendor, 'SAXON '))">
  164. <xsl:message terminate="yes">
  165. <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
  166. <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
  167. </xsl:message>
  168. </xsl:if>
  169. <xsl:if test="$kimber.imported = 0">
  170. <xsl:message terminate="yes">
  171. <xsl:text>ERROR: the 'kimber' index method requires the&#xA;</xsl:text>
  172. <xsl:text>kimber index extensions be imported:&#xA;</xsl:text>
  173. <xsl:text> xsl:import href="fo/autoidx-kimber.xsl"</xsl:text>
  174. </xsl:message>
  175. </xsl:if>
  176. </xsl:template>
  177. <xsl:template match="indexterm" mode="index-div-basic">
  178. <xsl:param name="scope" select="."/>
  179. <xsl:param name="role" select="''"/>
  180. <xsl:param name="type" select="''"/>
  181. <xsl:variable name="key"
  182. select="translate(substring(&primary;, 1, 1),
  183. &lowercase;,&uppercase;)"/>
  184. <xsl:if test="key('letter', $key)[&scope;]
  185. [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  186. <fo:block>
  187. <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
  188. <xsl:call-template name="indexdiv.title">
  189. <xsl:with-param name="titlecontent">
  190. <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
  191. </xsl:with-param>
  192. </xsl:call-template>
  193. </xsl:if>
  194. <fo:block xsl:use-attribute-sets="index.entry.properties">
  195. <xsl:apply-templates select="key('letter', $key)[&scope;]
  196. [count(.|key('primary', &primary;)
  197. [&scope;][1])=1]"
  198. mode="index-primary">
  199. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  200. <xsl:with-param name="scope" select="$scope"/>
  201. <xsl:with-param name="role" select="$role"/>
  202. <xsl:with-param name="type" select="$type"/>
  203. </xsl:apply-templates>
  204. </fo:block>
  205. </fo:block>
  206. </xsl:if>
  207. </xsl:template>
  208. <xsl:template match="indexterm" mode="index-symbol-div">
  209. <xsl:param name="scope" select="."/>
  210. <xsl:param name="role" select="''"/>
  211. <xsl:param name="type" select="''"/>
  212. <xsl:variable name="key"
  213. select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  214. <fo:block xsl:use-attribute-sets="index.entry.properties">
  215. <xsl:apply-templates select="key('letter', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]"
  216. mode="index-primary">
  217. <xsl:with-param name="scope" select="$scope"/>
  218. <xsl:with-param name="role" select="$role"/>
  219. <xsl:with-param name="type" select="$type"/>
  220. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  221. </xsl:apply-templates>
  222. </fo:block>
  223. </xsl:template>
  224. <xsl:template match="indexterm" mode="index-primary">
  225. <xsl:param name="scope" select="."/>
  226. <xsl:param name="role" select="''"/>
  227. <xsl:param name="type" select="''"/>
  228. <xsl:variable name="key" select="&primary;"/>
  229. <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
  230. <xsl:variable name="term.separator">
  231. <xsl:call-template name="index.separator">
  232. <xsl:with-param name="key" select="'index.term.separator'"/>
  233. </xsl:call-template>
  234. </xsl:variable>
  235. <xsl:variable name="range.separator">
  236. <xsl:call-template name="index.separator">
  237. <xsl:with-param name="key" select="'index.range.separator'"/>
  238. </xsl:call-template>
  239. </xsl:variable>
  240. <xsl:variable name="number.separator">
  241. <xsl:call-template name="index.separator">
  242. <xsl:with-param name="key" select="'index.number.separator'"/>
  243. </xsl:call-template>
  244. </xsl:variable>
  245. <fo:block>
  246. <xsl:if test="$axf.extensions != 0">
  247. <xsl:attribute name="axf:suppress-duplicate-page-number">true</xsl:attribute>
  248. </xsl:if>
  249. <xsl:for-each select="$refs/primary">
  250. <xsl:if test="@id or @xml:id">
  251. <fo:inline id="{(@id|@xml:id)[1]}"/>
  252. </xsl:if>
  253. </xsl:for-each>
  254. <xsl:value-of select="primary"/>
  255. <xsl:choose>
  256. <xsl:when test="$xep.extensions != 0">
  257. <xsl:if test="$refs[not(see) and not(secondary)]">
  258. <xsl:copy-of select="$term.separator"/>
  259. <xsl:variable name="primary" select="&primary;"/>
  260. <xsl:variable name="primary.significant" select="concat(&primary;, $significant.flag)"/>
  261. <rx:page-index list-separator="{$number.separator}"
  262. range-separator="{$range.separator}">
  263. <xsl:if test="$refs[@significance='preferred'][not(see) and not(secondary)]">
  264. <rx:index-item xsl:use-attribute-sets="index.preferred.page.properties xep.index.item.properties"
  265. ref-key="{$primary.significant}"/>
  266. </xsl:if>
  267. <xsl:if test="$refs[not(@significance) or @significance!='preferred'][not(see) and not(secondary)]">
  268. <rx:index-item xsl:use-attribute-sets="xep.index.item.properties"
  269. ref-key="{$primary}"/>
  270. </xsl:if>
  271. </rx:page-index>
  272. </xsl:if>
  273. </xsl:when>
  274. <xsl:otherwise>
  275. <xsl:variable name="page-number-citations">
  276. <xsl:for-each select="$refs[not(see)
  277. and not(secondary)]">
  278. <xsl:apply-templates select="." mode="reference">
  279. <xsl:with-param name="scope" select="$scope"/>
  280. <xsl:with-param name="role" select="$role"/>
  281. <xsl:with-param name="type" select="$type"/>
  282. <xsl:with-param name="position" select="position()"/>
  283. </xsl:apply-templates>
  284. </xsl:for-each>
  285. </xsl:variable>
  286. <xsl:copy-of select="$page-number-citations"/>
  287. </xsl:otherwise>
  288. </xsl:choose>
  289. <xsl:if test="$refs[not(secondary)]/*[self::see]">
  290. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[&scope;][1])]"
  291. mode="index-see">
  292. <xsl:with-param name="scope" select="$scope"/>
  293. <xsl:with-param name="role" select="$role"/>
  294. <xsl:with-param name="type" select="$type"/>
  295. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  296. </xsl:apply-templates>
  297. </xsl:if>
  298. </fo:block>
  299. <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::seealso]">
  300. <fo:block start-indent="1pc">
  301. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[&scope;][1])]"
  302. mode="index-seealso">
  303. <xsl:with-param name="scope" select="$scope"/>
  304. <xsl:with-param name="role" select="$role"/>
  305. <xsl:with-param name="type" select="$type"/>
  306. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  307. </xsl:apply-templates>
  308. <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[&scope;][1]) = 1]"
  309. mode="index-secondary">
  310. <xsl:with-param name="scope" select="$scope"/>
  311. <xsl:with-param name="role" select="$role"/>
  312. <xsl:with-param name="type" select="$type"/>
  313. <xsl:sort select="translate(&secondary;, &lowercase;, &uppercase;)"/>
  314. </xsl:apply-templates>
  315. </fo:block>
  316. </xsl:if>
  317. </xsl:template>
  318. <xsl:template match="indexterm" mode="index-secondary">
  319. <xsl:param name="scope" select="."/>
  320. <xsl:param name="role" select="''"/>
  321. <xsl:param name="type" select="''"/>
  322. <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
  323. <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
  324. <xsl:variable name="term.separator">
  325. <xsl:call-template name="index.separator">
  326. <xsl:with-param name="key" select="'index.term.separator'"/>
  327. </xsl:call-template>
  328. </xsl:variable>
  329. <xsl:variable name="range.separator">
  330. <xsl:call-template name="index.separator">
  331. <xsl:with-param name="key" select="'index.range.separator'"/>
  332. </xsl:call-template>
  333. </xsl:variable>
  334. <xsl:variable name="number.separator">
  335. <xsl:call-template name="index.separator">
  336. <xsl:with-param name="key" select="'index.number.separator'"/>
  337. </xsl:call-template>
  338. </xsl:variable>
  339. <fo:block>
  340. <xsl:if test="$axf.extensions != 0">
  341. <xsl:attribute name="axf:suppress-duplicate-page-number">true</xsl:attribute>
  342. </xsl:if>
  343. <xsl:for-each select="$refs/secondary">
  344. <xsl:if test="@id or @xml:id">
  345. <fo:inline id="{(@id|@xml:id)[1]}"/>
  346. </xsl:if>
  347. </xsl:for-each>
  348. <xsl:value-of select="secondary"/>
  349. <xsl:choose>
  350. <xsl:when test="$xep.extensions != 0">
  351. <xsl:if test="$refs[not(see) and not(tertiary)]">
  352. <xsl:copy-of select="$term.separator"/>
  353. <xsl:variable name="primary" select="&primary;"/>
  354. <xsl:variable name="secondary" select="&secondary;"/>
  355. <xsl:variable name="primary.significant" select="concat(&primary;, $significant.flag)"/>
  356. <rx:page-index list-separator="{$number.separator}"
  357. range-separator="{$range.separator}">
  358. <xsl:if test="$refs[@significance='preferred'][not(see) and not(tertiary)]">
  359. <rx:index-item xsl:use-attribute-sets="index.preferred.page.properties xep.index.item.properties">
  360. <xsl:attribute name="ref-key">
  361. <xsl:value-of select="$primary.significant"/>
  362. <xsl:text>, </xsl:text>
  363. <xsl:value-of select="$secondary"/>
  364. </xsl:attribute>
  365. </rx:index-item>
  366. </xsl:if>
  367. <xsl:if test="$refs[not(@significance) or @significance!='preferred'][not(see) and not(tertiary)]">
  368. <rx:index-item xsl:use-attribute-sets="xep.index.item.properties">
  369. <xsl:attribute name="ref-key">
  370. <xsl:value-of select="$primary"/>
  371. <xsl:text>, </xsl:text>
  372. <xsl:value-of select="$secondary"/>
  373. </xsl:attribute>
  374. </rx:index-item>
  375. </xsl:if>
  376. </rx:page-index>
  377. </xsl:if>
  378. </xsl:when>
  379. <xsl:otherwise>
  380. <xsl:variable name="page-number-citations">
  381. <xsl:for-each select="$refs[not(see)
  382. and not(tertiary)]">
  383. <xsl:apply-templates select="." mode="reference">
  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:with-param name="position" select="position()"/>
  388. </xsl:apply-templates>
  389. </xsl:for-each>
  390. </xsl:variable>
  391. <xsl:copy-of select="$page-number-citations"/>
  392. </xsl:otherwise>
  393. </xsl:choose>
  394. <xsl:if test="$refs[not(tertiary)]/*[self::see]">
  395. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[&scope;][1])]"
  396. mode="index-see">
  397. <xsl:with-param name="scope" select="$scope"/>
  398. <xsl:with-param name="role" select="$role"/>
  399. <xsl:with-param name="type" select="$type"/>
  400. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  401. </xsl:apply-templates>
  402. </xsl:if>
  403. </fo:block>
  404. <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::seealso]">
  405. <fo:block start-indent="2pc">
  406. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[&scope;][1])]"
  407. mode="index-seealso">
  408. <xsl:with-param name="scope" select="$scope"/>
  409. <xsl:with-param name="role" select="$role"/>
  410. <xsl:with-param name="type" select="$type"/>
  411. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  412. </xsl:apply-templates>
  413. <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[&scope;][1]) = 1]"
  414. mode="index-tertiary">
  415. <xsl:with-param name="scope" select="$scope"/>
  416. <xsl:with-param name="role" select="$role"/>
  417. <xsl:with-param name="type" select="$type"/>
  418. <xsl:sort select="translate(&tertiary;, &lowercase;, &uppercase;)"/>
  419. </xsl:apply-templates>
  420. </fo:block>
  421. </xsl:if>
  422. </xsl:template>
  423. <xsl:template match="indexterm" mode="index-tertiary">
  424. <xsl:param name="scope" select="."/>
  425. <xsl:param name="role" select="''"/>
  426. <xsl:param name="type" select="''"/>
  427. <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
  428. <xsl:variable name="refs" select="key('tertiary', $key)[&scope;]"/>
  429. <xsl:variable name="term.separator">
  430. <xsl:call-template name="index.separator">
  431. <xsl:with-param name="key" select="'index.term.separator'"/>
  432. </xsl:call-template>
  433. </xsl:variable>
  434. <xsl:variable name="range.separator">
  435. <xsl:call-template name="index.separator">
  436. <xsl:with-param name="key" select="'index.range.separator'"/>
  437. </xsl:call-template>
  438. </xsl:variable>
  439. <xsl:variable name="number.separator">
  440. <xsl:call-template name="index.separator">
  441. <xsl:with-param name="key" select="'index.number.separator'"/>
  442. </xsl:call-template>
  443. </xsl:variable>
  444. <fo:block>
  445. <xsl:if test="$axf.extensions != 0">
  446. <xsl:attribute name="axf:suppress-duplicate-page-number">true</xsl:attribute>
  447. </xsl:if>
  448. <xsl:for-each select="$refs/tertiary">
  449. <xsl:if test="@id or @xml:id">
  450. <fo:inline id="{(@id|@xml:id)[1]}"/>
  451. </xsl:if>
  452. </xsl:for-each>
  453. <xsl:value-of select="tertiary"/>
  454. <xsl:choose>
  455. <xsl:when test="$xep.extensions != 0">
  456. <xsl:if test="$refs[not(see)]">
  457. <xsl:copy-of select="$term.separator"/>
  458. <xsl:variable name="primary" select="&primary;"/>
  459. <xsl:variable name="secondary" select="&secondary;"/>
  460. <xsl:variable name="tertiary" select="&tertiary;"/>
  461. <xsl:variable name="primary.significant" select="concat(&primary;, $significant.flag)"/>
  462. <rx:page-index list-separator="{$number.separator}"
  463. range-separator="{$range.separator}">
  464. <xsl:if test="$refs[@significance='preferred'][not(see)]">
  465. <rx:index-item xsl:use-attribute-sets="index.preferred.page.properties xep.index.item.properties">
  466. <xsl:attribute name="ref-key">
  467. <xsl:value-of select="$primary.significant"/>
  468. <xsl:text>, </xsl:text>
  469. <xsl:value-of select="$secondary"/>
  470. <xsl:text>, </xsl:text>
  471. <xsl:value-of select="$tertiary"/>
  472. </xsl:attribute>
  473. </rx:index-item>
  474. </xsl:if>
  475. <xsl:if test="$refs[not(@significance) or @significance!='preferred'][not(see)]">
  476. <rx:index-item xsl:use-attribute-sets="xep.index.item.properties">
  477. <xsl:attribute name="ref-key">
  478. <xsl:value-of select="$primary"/>
  479. <xsl:text>, </xsl:text>
  480. <xsl:value-of select="$secondary"/>
  481. <xsl:text>, </xsl:text>
  482. <xsl:value-of select="$tertiary"/>
  483. </xsl:attribute>
  484. </rx:index-item>
  485. </xsl:if>
  486. </rx:page-index>
  487. </xsl:if>
  488. </xsl:when>
  489. <xsl:otherwise>
  490. <xsl:variable name="page-number-citations">
  491. <xsl:for-each select="$refs[not(see)]">
  492. <xsl:apply-templates select="." mode="reference">
  493. <xsl:with-param name="scope" select="$scope"/>
  494. <xsl:with-param name="role" select="$role"/>
  495. <xsl:with-param name="type" select="$type"/>
  496. <xsl:with-param name="position" select="position()"/>
  497. </xsl:apply-templates>
  498. </xsl:for-each>
  499. </xsl:variable>
  500. <xsl:copy-of select="$page-number-citations"/>
  501. </xsl:otherwise>
  502. </xsl:choose>
  503. <xsl:if test="$refs/see">
  504. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[&scope;][1])]"
  505. mode="index-see">
  506. <xsl:with-param name="scope" select="$scope"/>
  507. <xsl:with-param name="role" select="$role"/>
  508. <xsl:with-param name="type" select="$type"/>
  509. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  510. </xsl:apply-templates>
  511. </xsl:if>
  512. </fo:block>
  513. <xsl:if test="$refs/seealso">
  514. <fo:block>
  515. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[&scope;][1])]"
  516. mode="index-seealso">
  517. <xsl:with-param name="scope" select="$scope"/>
  518. <xsl:with-param name="role" select="$role"/>
  519. <xsl:with-param name="type" select="$type"/>
  520. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  521. </xsl:apply-templates>
  522. </fo:block>
  523. </xsl:if>
  524. </xsl:template>
  525. <xsl:template match="indexterm" mode="reference">
  526. <xsl:param name="scope" select="."/>
  527. <xsl:param name="role" select="''"/>
  528. <xsl:param name="type" select="''"/>
  529. <xsl:param name="position" select="0"/>
  530. <xsl:param name="separator" select="''"/>
  531. <xsl:variable name="term.separator">
  532. <xsl:call-template name="index.separator">
  533. <xsl:with-param name="key" select="'index.term.separator'"/>
  534. </xsl:call-template>
  535. </xsl:variable>
  536. <xsl:variable name="range.separator">
  537. <xsl:call-template name="index.separator">
  538. <xsl:with-param name="key" select="'index.range.separator'"/>
  539. </xsl:call-template>
  540. </xsl:variable>
  541. <xsl:variable name="number.separator">
  542. <xsl:call-template name="index.separator">
  543. <xsl:with-param name="key" select="'index.number.separator'"/>
  544. </xsl:call-template>
  545. </xsl:variable>
  546. <xsl:choose>
  547. <xsl:when test="$separator != ''">
  548. <xsl:value-of select="$separator"/>
  549. </xsl:when>
  550. <xsl:when test="$position = 1">
  551. <xsl:value-of select="$term.separator"/>
  552. </xsl:when>
  553. <xsl:otherwise>
  554. <xsl:value-of select="$number.separator"/>
  555. </xsl:otherwise>
  556. </xsl:choose>
  557. <xsl:choose>
  558. <xsl:when test="@zone and string(@zone)">
  559. <xsl:call-template name="reference">
  560. <xsl:with-param name="zones" select="normalize-space(@zone)"/>
  561. <xsl:with-param name="scope" select="$scope"/>
  562. <xsl:with-param name="role" select="$role"/>
  563. <xsl:with-param name="type" select="$type"/>
  564. </xsl:call-template>
  565. </xsl:when>
  566. <xsl:when test="ancestor::*[contains(local-name(),'info') and not(starts-with(local-name(),'info'))]">
  567. <xsl:call-template name="info.reference">
  568. <xsl:with-param name="scope" select="$scope"/>
  569. <xsl:with-param name="role" select="$role"/>
  570. <xsl:with-param name="type" select="$type"/>
  571. </xsl:call-template>
  572. </xsl:when>
  573. <xsl:otherwise>
  574. <xsl:variable name="id">
  575. <xsl:call-template name="object.id"/>
  576. </xsl:variable>
  577. <fo:basic-link internal-destination="{$id}"
  578. xsl:use-attribute-sets="index.page.number.properties">
  579. <fo:page-number-citation ref-id="{$id}"/>
  580. </fo:basic-link>
  581. <xsl:if test="key('endofrange', $id)[&scope;]">
  582. <xsl:apply-templates select="key('endofrange', $id)[&scope;][last()]"
  583. mode="reference">
  584. <xsl:with-param name="scope" select="$scope"/>
  585. <xsl:with-param name="role" select="$role"/>
  586. <xsl:with-param name="type" select="$type"/>
  587. <xsl:with-param name="separator" select="$range.separator"/>
  588. </xsl:apply-templates>
  589. </xsl:if>
  590. </xsl:otherwise>
  591. </xsl:choose>
  592. </xsl:template>
  593. <xsl:template name="reference">
  594. <xsl:param name="scope" select="."/>
  595. <xsl:param name="role" select="''"/>
  596. <xsl:param name="type" select="''"/>
  597. <xsl:param name="zones"/>
  598. <xsl:variable name="number.separator">
  599. <xsl:call-template name="index.separator">
  600. <xsl:with-param name="key" select="'index.number.separator'"/>
  601. </xsl:call-template>
  602. </xsl:variable>
  603. <xsl:choose>
  604. <xsl:when test="contains($zones, ' ')">
  605. <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
  606. <xsl:variable name="target" select="key('id', $zone)"/>
  607. <xsl:variable name="id">
  608. <xsl:call-template name="object.id">
  609. <xsl:with-param name="object" select="$target[1]"/>
  610. </xsl:call-template>
  611. </xsl:variable>
  612. <fo:basic-link internal-destination="{$id}"
  613. xsl:use-attribute-sets="index.page.number.properties">
  614. <fo:page-number-citation ref-id="{$id}"/>
  615. </fo:basic-link>
  616. <xsl:copy-of select="$number.separator"/>
  617. <xsl:call-template name="reference">
  618. <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
  619. <xsl:with-param name="scope" select="$scope"/>
  620. <xsl:with-param name="role" select="$role"/>
  621. <xsl:with-param name="type" select="$type"/>
  622. </xsl:call-template>
  623. </xsl:when>
  624. <xsl:otherwise>
  625. <xsl:variable name="zone" select="$zones"/>
  626. <xsl:variable name="target" select="key('id', $zone)"/>
  627. <xsl:variable name="id">
  628. <xsl:call-template name="object.id">
  629. <xsl:with-param name="object" select="$target[1]"/>
  630. </xsl:call-template>
  631. </xsl:variable>
  632. <fo:basic-link internal-destination="{$id}"
  633. xsl:use-attribute-sets="index.page.number.properties">
  634. <fo:page-number-citation ref-id="{$id}"/>
  635. </fo:basic-link>
  636. </xsl:otherwise>
  637. </xsl:choose>
  638. </xsl:template>
  639. <xsl:template name="info.reference">
  640. <!-- This is not perfect. It doesn't treat indexterm inside info element as a range covering whole parent of info.
  641. It also not work when there is no ID generated for parent element. But it works in the most common cases. -->
  642. <xsl:param name="scope" select="."/>
  643. <xsl:param name="role" select="''"/>
  644. <xsl:param name="type" select="''"/>
  645. <xsl:variable name="target" select="(ancestor::appendix|ancestor::article|ancestor::bibliography|ancestor::book|
  646. ancestor::chapter|ancestor::glossary|ancestor::part|ancestor::preface|
  647. ancestor::refentry|ancestor::reference|ancestor::refsect1|ancestor::refsect2|
  648. ancestor::refsect3|ancestor::refsection|ancestor::refsynopsisdiv|
  649. ancestor::sect1|ancestor::sect2|ancestor::sect3|ancestor::sect4|ancestor::sect5|
  650. ancestor::section|ancestor::setindex|ancestor::set|ancestor::sidebar|ancestor::mediaobject)[&scope;]"/>
  651. <xsl:variable name="id">
  652. <xsl:call-template name="object.id">
  653. <xsl:with-param name="object" select="$target[position() = last()]"/>
  654. </xsl:call-template>
  655. </xsl:variable>
  656. <fo:basic-link internal-destination="{$id}"
  657. xsl:use-attribute-sets="index.page.number.properties">
  658. <fo:page-number-citation ref-id="{$id}"/>
  659. </fo:basic-link>
  660. </xsl:template>
  661. <xsl:template match="indexterm" mode="index-see">
  662. <xsl:param name="scope" select="."/>
  663. <xsl:param name="role" select="''"/>
  664. <xsl:param name="type" select="''"/>
  665. <fo:inline>
  666. <xsl:text> (</xsl:text>
  667. <xsl:call-template name="gentext">
  668. <xsl:with-param name="key" select="'see'"/>
  669. </xsl:call-template>
  670. <xsl:text> </xsl:text>
  671. <xsl:value-of select="see"/>
  672. <xsl:text>)</xsl:text>
  673. </fo:inline>
  674. </xsl:template>
  675. <xsl:template match="indexterm" mode="index-seealso">
  676. <xsl:param name="scope" select="."/>
  677. <xsl:param name="role" select="''"/>
  678. <xsl:param name="type" select="''"/>
  679. <xsl:for-each select="seealso">
  680. <xsl:sort select="translate(., &lowercase;, &uppercase;)"/>
  681. <fo:block>
  682. <xsl:text>(</xsl:text>
  683. <xsl:call-template name="gentext">
  684. <xsl:with-param name="key" select="'seealso'"/>
  685. </xsl:call-template>
  686. <xsl:text> </xsl:text>
  687. <xsl:value-of select="."/>
  688. <xsl:text>)</xsl:text>
  689. </fo:block>
  690. </xsl:for-each>
  691. </xsl:template>
  692. <!-- ====================================================================== -->
  693. <xsl:template name="generate-index-markup">
  694. <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
  695. <xsl:param name="role" select="@role"/>
  696. <xsl:param name="type" select="@type"/>
  697. <xsl:variable name="terms" select="$scope//indexterm[count(.|key('letter',
  698. translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[&scope;][1]) = 1]"/>
  699. <xsl:variable name="alphabetical"
  700. select="$terms[contains(concat(&lowercase;, &uppercase;),
  701. substring(&primary;, 1, 1))]"/>
  702. <xsl:variable name="others" select="$terms[not(contains(concat(&lowercase;,
  703. &uppercase;),
  704. substring(&primary;, 1, 1)))]"/>
  705. <xsl:text>&lt;index&gt;&#10;</xsl:text>
  706. <xsl:if test="$others">
  707. <xsl:text>&#10;&lt;indexdiv&gt;&#10;</xsl:text>
  708. <xsl:text>&lt;title&gt;</xsl:text>
  709. <xsl:call-template name="gentext">
  710. <xsl:with-param name="key" select="'index symbols'"/>
  711. </xsl:call-template>
  712. <xsl:text>&lt;/title&gt;&#10;</xsl:text>
  713. <xsl:apply-templates select="$others[count(.|key('primary',
  714. &primary;)[&scope;][1]) = 1]"
  715. mode="index-symbol-div-markup">
  716. <xsl:with-param name="scope" select="$scope"/>
  717. <xsl:with-param name="role" select="$role"/>
  718. <xsl:with-param name="type" select="$type"/>
  719. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  720. </xsl:apply-templates>
  721. <xsl:text>&lt;/indexdiv&gt;&#10;</xsl:text>
  722. </xsl:if>
  723. <xsl:apply-templates select="$alphabetical[count(.|key('letter',
  724. translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[&scope;][1]) = 1]"
  725. mode="index-div-markup">
  726. <xsl:with-param name="scope" select="$scope"/>
  727. <xsl:with-param name="role" select="$role"/>
  728. <xsl:with-param name="type" select="$type"/>
  729. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  730. </xsl:apply-templates>
  731. <xsl:text>&lt;/index&gt;&#10;</xsl:text>
  732. </xsl:template>
  733. <xsl:template match="*" mode="index-markup">
  734. <xsl:param name="scope" select="."/>
  735. <xsl:param name="role" select="''"/>
  736. <xsl:param name="type" select="''"/>
  737. <xsl:text>&lt;</xsl:text>
  738. <xsl:value-of select="local-name(.)"/>
  739. <xsl:text>&gt;&#10;</xsl:text>
  740. <xsl:apply-templates mode="index-markup">
  741. <xsl:with-param name="scope" select="$scope"/>
  742. <xsl:with-param name="role" select="$role"/>
  743. <xsl:with-param name="type" select="$type"/>
  744. </xsl:apply-templates>
  745. </xsl:template>
  746. <xsl:template match="indexterm" mode="index-div-markup">
  747. <xsl:param name="scope" select="."/>
  748. <xsl:param name="role" select="''"/>
  749. <xsl:param name="type" select="''"/>
  750. <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  751. <xsl:text>&#10;&lt;indexdiv&gt;&#10;</xsl:text>
  752. <xsl:text>&lt;title&gt;</xsl:text>
  753. <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
  754. <xsl:text>&lt;/title&gt;&#10;</xsl:text>
  755. <xsl:apply-templates select="key('letter', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]"
  756. mode="index-primary-markup">
  757. <xsl:with-param name="scope" select="$scope"/>
  758. <xsl:with-param name="role" select="$role"/>
  759. <xsl:with-param name="type" select="$type"/>
  760. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  761. </xsl:apply-templates>
  762. <xsl:text>&lt;/indexdiv&gt;&#10;</xsl:text>
  763. </xsl:template>
  764. <xsl:template match="indexterm" mode="index-symbol-div-markup">
  765. <xsl:param name="scope" select="."/>
  766. <xsl:param name="role" select="''"/>
  767. <xsl:param name="type" select="''"/>
  768. <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  769. <xsl:apply-templates select="key('letter', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]"
  770. mode="index-primary-markup">
  771. <xsl:with-param name="scope" select="$scope"/>
  772. <xsl:with-param name="role" select="$role"/>
  773. <xsl:with-param name="type" select="$type"/>
  774. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  775. </xsl:apply-templates>
  776. </xsl:template>
  777. <xsl:template match="indexterm" mode="index-primary-markup">
  778. <xsl:param name="scope" select="."/>
  779. <xsl:param name="role" select="''"/>
  780. <xsl:param name="type" select="''"/>
  781. <xsl:variable name="key" select="&primary;"/>
  782. <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
  783. <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
  784. <xsl:text>&#10;&lt;indexentry&gt;&#10;</xsl:text>
  785. <xsl:text>&lt;primaryie&gt;</xsl:text>
  786. <xsl:text>&lt;phrase&gt;</xsl:text>
  787. <xsl:call-template name="escape-text">
  788. <xsl:with-param name="text" select="string(primary)"/>
  789. </xsl:call-template>
  790. <xsl:text>&lt;/phrase&gt;</xsl:text>
  791. <xsl:if test="$pages">,</xsl:if>
  792. <xsl:text>&#10;</xsl:text>
  793. <xsl:for-each select="$pages">
  794. <xsl:apply-templates select="." mode="reference-markup">
  795. <xsl:with-param name="scope" select="$scope"/>
  796. <xsl:with-param name="role" select="$role"/>
  797. <xsl:with-param name="type" select="$type"/>
  798. </xsl:apply-templates>
  799. </xsl:for-each>
  800. <xsl:text>&lt;/primaryie&gt;&#10;</xsl:text>
  801. <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::see or self::seealso]">
  802. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[&scope;][1])]"
  803. mode="index-see-markup">
  804. <xsl:with-param name="scope" select="$scope"/>
  805. <xsl:with-param name="role" select="$role"/>
  806. <xsl:with-param name="type" select="$type"/>
  807. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  808. </xsl:apply-templates>
  809. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[&scope;][1])]"
  810. mode="index-seealso-markup">
  811. <xsl:with-param name="scope" select="$scope"/>
  812. <xsl:with-param name="role" select="$role"/>
  813. <xsl:with-param name="type" select="$type"/>
  814. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  815. </xsl:apply-templates>
  816. <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[&scope;][1]) = 1]"
  817. mode="index-secondary-markup">
  818. <xsl:with-param name="scope" select="$scope"/>
  819. <xsl:with-param name="role" select="$role"/>
  820. <xsl:with-param name="type" select="$type"/>
  821. <xsl:sort select="translate(&secondary;, &lowercase;, &uppercase;)"/>
  822. </xsl:apply-templates>
  823. </xsl:if>
  824. <xsl:text>&lt;/indexentry&gt;&#10;</xsl:text>
  825. </xsl:template>
  826. <xsl:template match="indexterm" mode="index-secondary-markup">
  827. <xsl:param name="scope" select="."/>
  828. <xsl:param name="role" select="''"/>
  829. <xsl:param name="type" select="''"/>
  830. <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
  831. <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
  832. <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
  833. <xsl:text>&lt;secondaryie&gt;</xsl:text>
  834. <xsl:text>&lt;phrase&gt;</xsl:text>
  835. <xsl:call-template name="escape-text">
  836. <xsl:with-param name="text" select="string(secondary)"/>
  837. </xsl:call-template>
  838. <xsl:text>&lt;/phrase&gt;</xsl:text>
  839. <xsl:if test="$pages">,</xsl:if>
  840. <xsl:text>&#10;</xsl:text>
  841. <xsl:for-each select="$pages">
  842. <xsl:apply-templates select="." mode="reference-markup">
  843. <xsl:with-param name="scope" select="$scope"/>
  844. <xsl:with-param name="role" select="$role"/>
  845. <xsl:with-param name="type" select="$type"/>
  846. </xsl:apply-templates>
  847. </xsl:for-each>
  848. <xsl:text>&lt;/secondaryie&gt;&#10;</xsl:text>
  849. <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::see or self::seealso]">
  850. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[&scope;][1])]"
  851. mode="index-see-markup">
  852. <xsl:with-param name="scope" select="$scope"/>
  853. <xsl:with-param name="role" select="$role"/>
  854. <xsl:with-param name="type" select="$type"/>
  855. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  856. </xsl:apply-templates>
  857. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[&scope;][1])]"
  858. mode="index-seealso-markup">
  859. <xsl:with-param name="scope" select="$scope"/>
  860. <xsl:with-param name="role" select="$role"/>
  861. <xsl:with-param name="type" select="$type"/>
  862. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  863. </xsl:apply-templates>
  864. <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[&scope;][1]) = 1]"
  865. mode="index-tertiary-markup">
  866. <xsl:with-param name="scope" select="$scope"/>
  867. <xsl:with-param name="role" select="$role"/>
  868. <xsl:with-param name="type" select="$type"/>
  869. <xsl:sort select="translate(&tertiary;, &lowercase;, &uppercase;)"/>
  870. </xsl:apply-templates>
  871. </xsl:if>
  872. </xsl:template>
  873. <xsl:template match="indexterm" mode="index-tertiary-markup">
  874. <xsl:param name="scope" select="."/>
  875. <xsl:param name="role" select="''"/>
  876. <xsl:param name="type" select="''"/>
  877. <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
  878. <xsl:variable name="refs" select="key('tertiary', $key)[&scope;]"/>
  879. <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
  880. <xsl:text>&lt;tertiaryie&gt;</xsl:text>
  881. <xsl:text>&lt;phrase&gt;</xsl:text>
  882. <xsl:call-template name="escape-text">
  883. <xsl:with-param name="text" select="string(tertiary)"/>
  884. </xsl:call-template>
  885. <xsl:text>&lt;/phrase&gt;</xsl:text>
  886. <xsl:if test="$pages">,</xsl:if>
  887. <xsl:text>&#10;</xsl:text>
  888. <xsl:for-each select="$pages">
  889. <xsl:apply-templates select="." mode="reference-markup">
  890. <xsl:with-param name="scope" select="$scope"/>
  891. <xsl:with-param name="role" select="$role"/>
  892. <xsl:with-param name="type" select="$type"/>
  893. </xsl:apply-templates>
  894. </xsl:for-each>
  895. <xsl:text>&lt;/tertiaryie&gt;&#10;</xsl:text>
  896. <xsl:variable name="see" select="$refs/see | $refs/seealso"/>
  897. <xsl:if test="$see">
  898. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[&scope;][1])]"
  899. mode="index-see-markup">
  900. <xsl:with-param name="scope" select="$scope"/>
  901. <xsl:with-param name="role" select="$role"/>
  902. <xsl:with-param name="type" select="$type"/>
  903. <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
  904. </xsl:apply-templates>
  905. <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[&scope;][1])]"
  906. mode="index-seealso-markup">
  907. <xsl:with-param name="scope" select="$scope"/>
  908. <xsl:with-param name="role" select="$role"/>
  909. <xsl:with-param name="type" select="$type"/>
  910. <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
  911. </xsl:apply-templates>
  912. </xsl:if>
  913. </xsl:template>
  914. <xsl:template match="indexterm" mode="reference-markup">
  915. <xsl:param name="scope" select="."/>
  916. <xsl:param name="role" select="''"/>
  917. <xsl:param name="type" select="''"/>
  918. <xsl:choose>
  919. <xsl:when test="@zone and string(@zone)">
  920. <xsl:call-template name="reference-markup">
  921. <xsl:with-param name="zones" select="normalize-space(@zone)"/>
  922. <xsl:with-param name="scope" select="$scope"/>
  923. <xsl:with-param name="role" select="$role"/>
  924. <xsl:with-param name="type" select="$type"/>
  925. </xsl:call-template>
  926. </xsl:when>
  927. <xsl:otherwise>
  928. <xsl:variable name="id">
  929. <xsl:call-template name="object.id"/>
  930. </xsl:variable>
  931. <xsl:choose>
  932. <xsl:when test="@startref and @class='endofrange'">
  933. <xsl:text>&lt;phrase role="pageno"&gt;</xsl:text>
  934. <xsl:text>&lt;link linkend="</xsl:text>
  935. <xsl:value-of select="@startref"/>
  936. <xsl:text>"&gt;</xsl:text>
  937. <fo:basic-link internal-destination="{@startref}"
  938. xsl:use-attribute-sets="index.page.number.properties">
  939. <fo:page-number-citation ref-id="{@startref}"/>
  940. <xsl:text>-</xsl:text>
  941. <fo:page-number-citation ref-id="{$id}"/>
  942. </fo:basic-link>
  943. <xsl:text>&lt;/link&gt;</xsl:text>
  944. <xsl:text>&lt;/phrase&gt;&#10;</xsl:text>
  945. </xsl:when>
  946. <xsl:otherwise>
  947. <xsl:text>&lt;phrase role="pageno"&gt;</xsl:text>
  948. <xsl:if test="$id">
  949. <xsl:text>&lt;link linkend="</xsl:text>
  950. <xsl:value-of select="$id"/>
  951. <xsl:text>"&gt;</xsl:text>
  952. </xsl:if>
  953. <fo:basic-link internal-destination="{$id}"
  954. xsl:use-attribute-sets="index.page.number.properties">
  955. <fo:page-number-citation ref-id="{$id}"/>
  956. </fo:basic-link>
  957. <xsl:if test="$id">
  958. <xsl:text>&lt;/link&gt;</xsl:text>
  959. </xsl:if>
  960. <xsl:text>&lt;/phrase&gt;&#10;</xsl:text>
  961. </xsl:otherwise>
  962. </xsl:choose>
  963. </xsl:otherwise>
  964. </xsl:choose>
  965. </xsl:template>
  966. <xsl:template name="reference-markup">
  967. <xsl:param name="scope" select="."/>
  968. <xsl:param name="role" select="''"/>
  969. <xsl:param name="type" select="''"/>
  970. <xsl:param name="zones"/>
  971. <xsl:choose>
  972. <xsl:when test="contains($zones, ' ')">
  973. <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
  974. <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
  975. <xsl:variable name="id">
  976. <xsl:call-template name="object.id">
  977. <xsl:with-param name="object" select="$target[1]"/>
  978. </xsl:call-template>
  979. </xsl:variable>
  980. <xsl:text>&lt;phrase role="pageno"&gt;</xsl:text>
  981. <xsl:if test="$target[1]/@id or $target[1]/@xml:id">
  982. <xsl:text>&lt;link linkend="</xsl:text>
  983. <xsl:value-of select="$id"/>
  984. <xsl:text>"&gt;</xsl:text>
  985. </xsl:if>
  986. <fo:basic-link internal-destination="{$id}"
  987. xsl:use-attribute-sets="index.page.number.properties">
  988. <fo:page-number-citation ref-id="{$id}"/>
  989. </fo:basic-link>
  990. <xsl:if test="$target[1]/@id or $target[1]/@xml:id">
  991. <xsl:text>&lt;/link&gt;</xsl:text>
  992. </xsl:if>
  993. <xsl:text>&lt;/phrase&gt;&#10;</xsl:text>
  994. <xsl:call-template name="reference">
  995. <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
  996. <xsl:with-param name="scope" select="$scope"/>
  997. <xsl:with-param name="role" select="$role"/>
  998. <xsl:with-param name="type" select="$type"/>
  999. </xsl:call-template>
  1000. </xsl:when>
  1001. <xsl:otherwise>
  1002. <xsl:variable name="zone" select="$zones"/>
  1003. <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
  1004. <xsl:variable name="id">
  1005. <xsl:call-template name="object.id">
  1006. <xsl:with-param name="object" select="$target[1]"/>
  1007. </xsl:call-template>
  1008. </xsl:variable>
  1009. <xsl:text>&lt;phrase role="pageno"&gt;</xsl:text>
  1010. <xsl:if test="$target[1]/@id or target[1]/@xml:id">
  1011. <xsl:text>&lt;link linkend="</xsl:text>
  1012. <xsl:value-of select="$id"/>
  1013. <xsl:text>"&gt;</xsl:text>
  1014. </xsl:if>
  1015. <fo:basic-link internal-destination="{$id}"
  1016. xsl:use-attribute-sets="index.page.number.properties">
  1017. <fo:page-number-citation ref-id="{$id}"/>
  1018. </fo:basic-link>
  1019. <xsl:if test="$target[1]/@id or target[1]/@xml:id">
  1020. <xsl:text>&lt;/link&gt;</xsl:text>
  1021. </xsl:if>
  1022. <xsl:text>&lt;/phrase&gt;&#10;</xsl:text>
  1023. </xsl:otherwise>
  1024. </xsl:choose>
  1025. </xsl:template>
  1026. <xsl:template match="indexterm" mode="index-see-markup">
  1027. <xsl:param name="scope" select="."/>
  1028. <xsl:param name="role" select="''"/>
  1029. <xsl:param name="type" select="''"/>
  1030. <fo:block>
  1031. <xsl:text>&lt;seeie&gt;</xsl:text>
  1032. <xsl:text>&lt;phrase&gt;</xsl:text>
  1033. <xsl:call-template name="escape-text">
  1034. <xsl:with-param name="text" select="string(see)"/>
  1035. </xsl:call-template>
  1036. <xsl:text>&lt;/phrase&gt;</xsl:text>
  1037. <xsl:text>&lt;/seeie&gt;&#10;</xsl:text>
  1038. </fo:block>
  1039. </xsl:template>
  1040. <xsl:template match="indexterm" mode="index-seealso-markup">
  1041. <xsl:param name="scope" select="."/>
  1042. <xsl:param name="role" select="''"/>
  1043. <xsl:param name="type" select="''"/>
  1044. <fo:block>
  1045. <xsl:text>&lt;seealsoie&gt;</xsl:text>
  1046. <xsl:text>&lt;phrase&gt;</xsl:text>
  1047. <xsl:call-template name="escape-text">
  1048. <xsl:with-param name="text" select="string(seealso)"/>
  1049. </xsl:call-template>
  1050. <xsl:text>&lt;/phrase&gt;</xsl:text>
  1051. <xsl:text>&lt;/seealsoie&gt;&#10;</xsl:text>
  1052. </fo:block>
  1053. </xsl:template>
  1054. <xsl:template name="escape-text">
  1055. <xsl:param name="text" select="''"/>
  1056. <xsl:variable name="ltpos" select="substring-before($text, '&lt;')"/>
  1057. <xsl:variable name="amppos" select="substring-before($text, '&amp;')"/>
  1058. <xsl:choose>
  1059. <xsl:when test="contains($text,'&lt;') and contains($text, '&amp;')
  1060. and string-length($ltpos) &lt; string-length($amppos)">
  1061. <xsl:value-of select="$ltpos"/>
  1062. <xsl:text>&amp;lt;</xsl:text>
  1063. <xsl:call-template name="escape-text">
  1064. <xsl:with-param name="text" select="substring-after($text, '&lt;')"/>
  1065. </xsl:call-template>
  1066. </xsl:when>
  1067. <xsl:when test="contains($text,'&lt;') and contains($text, '&amp;')
  1068. and string-length($amppos) &lt; string-length($ltpos)">
  1069. <xsl:value-of select="$amppos"/>
  1070. <xsl:text>&amp;amp;</xsl:text>
  1071. <xsl:call-template name="escape-text">
  1072. <xsl:with-param name="text" select="substring-after($text, '&amp;')"/>
  1073. </xsl:call-template>
  1074. </xsl:when>
  1075. <xsl:when test="contains($text, '&lt;')">
  1076. <xsl:value-of select="$ltpos"/>
  1077. <xsl:text>&amp;lt;</xsl:text>
  1078. <xsl:call-template name="escape-text">
  1079. <xsl:with-param name="text" select="substring-after($text, '&lt;')"/>
  1080. </xsl:call-template>
  1081. </xsl:when>
  1082. <xsl:when test="contains($text, '&amp;')">
  1083. <xsl:value-of select="$amppos"/>
  1084. <xsl:text>&amp;amp;</xsl:text>
  1085. <xsl:call-template name="escape-text">
  1086. <xsl:with-param name="text" select="substring-after($text, '&amp;')"/>
  1087. </xsl:call-template>
  1088. </xsl:when>
  1089. <xsl:otherwise>
  1090. <xsl:value-of select="$text"/>
  1091. </xsl:otherwise>
  1092. </xsl:choose>
  1093. </xsl:template>
  1094. <xsl:template name="index.separator">
  1095. <xsl:param name="key" select="''"/>
  1096. <xsl:param name="lang">
  1097. <xsl:call-template name="l10n.language"/>
  1098. </xsl:param>
  1099. <xsl:choose>
  1100. <xsl:when test="$key = 'index.term.separator'">
  1101. <xsl:choose>
  1102. <!-- Use the override if not blank -->
  1103. <xsl:when test="$index.term.separator != ''">
  1104. <xsl:copy-of select="$index.term.separator"/>
  1105. </xsl:when>
  1106. <xsl:otherwise>
  1107. <xsl:call-template name="gentext.template">
  1108. <xsl:with-param name="lang" select="$lang"/>
  1109. <xsl:with-param name="context">index</xsl:with-param>
  1110. <xsl:with-param name="name">term-separator</xsl:with-param>
  1111. </xsl:call-template>
  1112. </xsl:otherwise>
  1113. </xsl:choose>
  1114. </xsl:when>
  1115. <xsl:when test="$key = 'index.number.separator'">
  1116. <xsl:choose>
  1117. <!-- Use the override if not blank -->
  1118. <xsl:when test="$index.number.separator != ''">
  1119. <xsl:copy-of select="$index.number.separator"/>
  1120. </xsl:when>
  1121. <xsl:otherwise>
  1122. <xsl:call-template name="gentext.template">
  1123. <xsl:with-param name="lang" select="$lang"/>
  1124. <xsl:with-param name="context">index</xsl:with-param>
  1125. <xsl:with-param name="name">number-separator</xsl:with-param>
  1126. </xsl:call-template>
  1127. </xsl:otherwise>
  1128. </xsl:choose>
  1129. </xsl:when>
  1130. <xsl:when test="$key = 'index.range.separator'">
  1131. <xsl:choose>
  1132. <!-- Use the override if not blank -->
  1133. <xsl:when test="$index.range.separator != ''">
  1134. <xsl:copy-of select="$index.range.separator"/>
  1135. </xsl:when>
  1136. <xsl:otherwise>
  1137. <xsl:call-template name="gentext.template">
  1138. <xsl:with-param name="lang" select="$lang"/>
  1139. <xsl:with-param name="context">index</xsl:with-param>
  1140. <xsl:with-param name="name">range-separator</xsl:with-param>
  1141. </xsl:call-template>
  1142. </xsl:otherwise>
  1143. </xsl:choose>
  1144. </xsl:when>
  1145. </xsl:choose>
  1146. </xsl:template>
  1147. </xsl:stylesheet>