autoidx.xsl 52 KB

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