1
0

index.xsl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. version='1.0'>
  10. <!-- ********************************************************************
  11. $Id: index.xsl 9286 2012-04-19 10:10:58Z bobstayton $
  12. ********************************************************************
  13. This file is part of the XSL DocBook Stylesheet distribution.
  14. See ../README or http://docbook.sf.net/release/xsl/current/ for
  15. copyright and other information.
  16. ******************************************************************** -->
  17. <!-- ==================================================================== -->
  18. <xsl:template match="index">
  19. <xsl:variable name="id">
  20. <xsl:call-template name="object.id"/>
  21. </xsl:variable>
  22. <xsl:if test="$generate.index != 0">
  23. <xsl:choose>
  24. <xsl:when test="$make.index.markup != 0">
  25. <fo:block>
  26. <xsl:call-template name="generate-index-markup">
  27. <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
  28. </xsl:call-template>
  29. </fo:block>
  30. </xsl:when>
  31. <xsl:otherwise>
  32. <fo:block id="{$id}">
  33. <xsl:call-template name="index.titlepage"/>
  34. </fo:block>
  35. <xsl:apply-templates/>
  36. <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
  37. <xsl:call-template name="generate-index">
  38. <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
  39. </xsl:call-template>
  40. </xsl:if>
  41. </xsl:otherwise>
  42. </xsl:choose>
  43. </xsl:if>
  44. </xsl:template>
  45. <xsl:template match="book/index|part/index">
  46. <xsl:variable name="id">
  47. <xsl:call-template name="object.id"/>
  48. </xsl:variable>
  49. <xsl:if test="$generate.index != 0">
  50. <xsl:variable name="master-reference">
  51. <xsl:call-template name="select.pagemaster">
  52. <xsl:with-param name="pageclass">
  53. <xsl:if test="$make.index.markup != 0">body</xsl:if>
  54. </xsl:with-param>
  55. </xsl:call-template>
  56. </xsl:variable>
  57. <fo:page-sequence hyphenate="{$hyphenate}"
  58. master-reference="{$master-reference}">
  59. <xsl:attribute name="language">
  60. <xsl:call-template name="l10n.language"/>
  61. </xsl:attribute>
  62. <xsl:attribute name="format">
  63. <xsl:call-template name="page.number.format">
  64. <xsl:with-param name="master-reference" select="$master-reference"/>
  65. </xsl:call-template>
  66. </xsl:attribute>
  67. <xsl:attribute name="initial-page-number">
  68. <xsl:call-template name="initial.page.number">
  69. <xsl:with-param name="master-reference" select="$master-reference"/>
  70. </xsl:call-template>
  71. </xsl:attribute>
  72. <xsl:attribute name="force-page-count">
  73. <xsl:call-template name="force.page.count">
  74. <xsl:with-param name="master-reference" select="$master-reference"/>
  75. </xsl:call-template>
  76. </xsl:attribute>
  77. <xsl:attribute name="hyphenation-character">
  78. <xsl:call-template name="gentext">
  79. <xsl:with-param name="key" select="'hyphenation-character'"/>
  80. </xsl:call-template>
  81. </xsl:attribute>
  82. <xsl:attribute name="hyphenation-push-character-count">
  83. <xsl:call-template name="gentext">
  84. <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
  85. </xsl:call-template>
  86. </xsl:attribute>
  87. <xsl:attribute name="hyphenation-remain-character-count">
  88. <xsl:call-template name="gentext">
  89. <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
  90. </xsl:call-template>
  91. </xsl:attribute>
  92. <xsl:apply-templates select="." mode="running.head.mode">
  93. <xsl:with-param name="master-reference" select="$master-reference"/>
  94. </xsl:apply-templates>
  95. <xsl:apply-templates select="." mode="running.foot.mode">
  96. <xsl:with-param name="master-reference" select="$master-reference"/>
  97. </xsl:apply-templates>
  98. <fo:flow flow-name="xsl-region-body">
  99. <xsl:call-template name="set.flow.properties">
  100. <xsl:with-param name="element" select="local-name(.)"/>
  101. <xsl:with-param name="master-reference" select="$master-reference"/>
  102. </xsl:call-template>
  103. <fo:block id="{$id}"
  104. xsl:use-attribute-sets="component.titlepage.properties">
  105. <xsl:call-template name="index.titlepage"/>
  106. </fo:block>
  107. <xsl:apply-templates/>
  108. <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
  109. <xsl:choose>
  110. <xsl:when test="$make.index.markup != 0">
  111. <fo:block wrap-option='no-wrap'
  112. white-space-collapse='false'
  113. xsl:use-attribute-sets="monospace.verbatim.properties"
  114. linefeed-treatment="preserve">
  115. <xsl:call-template name="generate-index-markup">
  116. <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
  117. </xsl:call-template>
  118. </fo:block>
  119. </xsl:when>
  120. <xsl:when test="indexentry|indexdiv/indexentry">
  121. <xsl:apply-templates/>
  122. </xsl:when>
  123. <xsl:otherwise>
  124. <xsl:call-template name="generate-index">
  125. <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
  126. </xsl:call-template>
  127. </xsl:otherwise>
  128. </xsl:choose>
  129. </xsl:if>
  130. </fo:flow>
  131. </fo:page-sequence>
  132. </xsl:if>
  133. </xsl:template>
  134. <xsl:template match="setindex">
  135. <xsl:variable name="id">
  136. <xsl:call-template name="object.id"/>
  137. </xsl:variable>
  138. <xsl:if test="$generate.index != 0">
  139. <xsl:variable name="master-reference">
  140. <xsl:call-template name="select.pagemaster">
  141. <xsl:with-param name="pageclass">
  142. <xsl:choose>
  143. <xsl:when test="$make.index.markup != 0">body</xsl:when>
  144. <xsl:otherwise>index</xsl:otherwise>
  145. </xsl:choose>
  146. </xsl:with-param>
  147. </xsl:call-template>
  148. </xsl:variable>
  149. <fo:page-sequence hyphenate="{$hyphenate}"
  150. master-reference="{$master-reference}">
  151. <xsl:attribute name="language">
  152. <xsl:call-template name="l10n.language"/>
  153. </xsl:attribute>
  154. <xsl:attribute name="format">
  155. <xsl:call-template name="page.number.format">
  156. <xsl:with-param name="master-reference" select="$master-reference"/>
  157. </xsl:call-template>
  158. </xsl:attribute>
  159. <xsl:attribute name="initial-page-number">
  160. <xsl:call-template name="initial.page.number">
  161. <xsl:with-param name="master-reference" select="$master-reference"/>
  162. </xsl:call-template>
  163. </xsl:attribute>
  164. <xsl:attribute name="force-page-count">
  165. <xsl:call-template name="force.page.count">
  166. <xsl:with-param name="master-reference" select="$master-reference"/>
  167. </xsl:call-template>
  168. </xsl:attribute>
  169. <xsl:attribute name="hyphenation-character">
  170. <xsl:call-template name="gentext">
  171. <xsl:with-param name="key" select="'hyphenation-character'"/>
  172. </xsl:call-template>
  173. </xsl:attribute>
  174. <xsl:attribute name="hyphenation-push-character-count">
  175. <xsl:call-template name="gentext">
  176. <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
  177. </xsl:call-template>
  178. </xsl:attribute>
  179. <xsl:attribute name="hyphenation-remain-character-count">
  180. <xsl:call-template name="gentext">
  181. <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
  182. </xsl:call-template>
  183. </xsl:attribute>
  184. <xsl:apply-templates select="." mode="running.head.mode">
  185. <xsl:with-param name="master-reference" select="$master-reference"/>
  186. </xsl:apply-templates>
  187. <xsl:apply-templates select="." mode="running.foot.mode">
  188. <xsl:with-param name="master-reference" select="$master-reference"/>
  189. </xsl:apply-templates>
  190. <fo:flow flow-name="xsl-region-body">
  191. <xsl:call-template name="set.flow.properties">
  192. <xsl:with-param name="element" select="local-name(.)"/>
  193. <xsl:with-param name="master-reference" select="$master-reference"/>
  194. </xsl:call-template>
  195. <fo:block id="{$id}">
  196. <xsl:call-template name="setindex.titlepage"/>
  197. </fo:block>
  198. <xsl:apply-templates/>
  199. <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
  200. <xsl:choose>
  201. <xsl:when test="$make.index.markup != 0">
  202. <fo:block wrap-option='no-wrap'
  203. white-space-collapse='false'
  204. xsl:use-attribute-sets="monospace.verbatim.properties"
  205. linefeed-treatment="preserve">
  206. <xsl:call-template name="generate-index-markup">
  207. <xsl:with-param name="scope" select="/"/>
  208. </xsl:call-template>
  209. </fo:block>
  210. </xsl:when>
  211. <xsl:when test="indexentry|indexdiv/indexentry">
  212. <xsl:apply-templates/>
  213. </xsl:when>
  214. <xsl:otherwise>
  215. <xsl:call-template name="generate-index">
  216. <xsl:with-param name="scope" select="/"/>
  217. </xsl:call-template>
  218. </xsl:otherwise>
  219. </xsl:choose>
  220. </xsl:if>
  221. </fo:flow>
  222. </fo:page-sequence>
  223. </xsl:if>
  224. </xsl:template>
  225. <xsl:template match="index/indexinfo"></xsl:template>
  226. <xsl:template match="index/info"></xsl:template>
  227. <xsl:template match="index/title"></xsl:template>
  228. <xsl:template match="index/subtitle"></xsl:template>
  229. <xsl:template match="index/titleabbrev"></xsl:template>
  230. <!-- ==================================================================== -->
  231. <xsl:template name="indexdiv.title">
  232. <xsl:param name="title"/>
  233. <xsl:param name="titlecontent"/>
  234. <fo:block xsl:use-attribute-sets="index.div.title.properties">
  235. <xsl:choose>
  236. <xsl:when test="$title">
  237. <xsl:apply-templates select="." mode="object.title.markup">
  238. <xsl:with-param name="allow-anchors" select="1"/>
  239. </xsl:apply-templates>
  240. </xsl:when>
  241. <xsl:otherwise>
  242. <xsl:copy-of select="$titlecontent"/>
  243. </xsl:otherwise>
  244. </xsl:choose>
  245. </fo:block>
  246. </xsl:template>
  247. <xsl:template match="indexdiv">
  248. <fo:block>
  249. <xsl:call-template name="indexdiv.titlepage"/>
  250. <xsl:apply-templates/>
  251. </fo:block>
  252. </xsl:template>
  253. <xsl:template match="indexdiv/title"/>
  254. <xsl:template match="indexdiv/subtitle"/>
  255. <xsl:template match="indexdiv/titleabbrev"/>
  256. <!-- ==================================================================== -->
  257. <!-- Text used for distiguishing between normal and significant entries -->
  258. <xsl:variable name="significant.flag">.tnacifingis</xsl:variable>
  259. <xsl:template match="indexterm" name="indexterm">
  260. <!-- Temporal workaround for bug in AXF -->
  261. <xsl:variable name="wrapper.name">
  262. <xsl:choose>
  263. <xsl:when test="$axf.extensions != 0 or $fop1.extensions != 0">
  264. <xsl:call-template name="inline.or.block"/>
  265. </xsl:when>
  266. <xsl:otherwise>fo:wrapper</xsl:otherwise>
  267. </xsl:choose>
  268. </xsl:variable>
  269. <xsl:element name="{$wrapper.name}">
  270. <xsl:attribute name="id">
  271. <xsl:call-template name="object.id"/>
  272. </xsl:attribute>
  273. <xsl:choose>
  274. <xsl:when test="$xep.extensions != 0">
  275. <xsl:attribute name="rx:key">
  276. <xsl:value-of select="&primary;"/>
  277. <xsl:if test="@significance='preferred'"><xsl:value-of select="$significant.flag"/></xsl:if>
  278. <xsl:if test="secondary">
  279. <xsl:text>, </xsl:text>
  280. <xsl:value-of select="&secondary;"/>
  281. </xsl:if>
  282. <xsl:if test="tertiary">
  283. <xsl:text>, </xsl:text>
  284. <xsl:value-of select="&tertiary;"/>
  285. </xsl:if>
  286. </xsl:attribute>
  287. </xsl:when>
  288. <xsl:otherwise>
  289. <xsl:comment>
  290. <xsl:call-template name="comment-escape-string">
  291. <xsl:with-param name="string">
  292. <xsl:value-of select="primary"/>
  293. <xsl:if test="secondary">
  294. <xsl:text>, </xsl:text>
  295. <xsl:value-of select="secondary"/>
  296. </xsl:if>
  297. <xsl:if test="tertiary">
  298. <xsl:text>, </xsl:text>
  299. <xsl:value-of select="tertiary"/>
  300. </xsl:if>
  301. </xsl:with-param>
  302. </xsl:call-template>
  303. </xsl:comment>
  304. </xsl:otherwise>
  305. </xsl:choose>
  306. </xsl:element>
  307. </xsl:template>
  308. <xsl:template match="indexterm[@class='startofrange']">
  309. <xsl:choose>
  310. <xsl:when test="$xep.extensions != 0">
  311. <rx:begin-index-range>
  312. <xsl:call-template name="anchor"/>
  313. <xsl:attribute name="rx:key">
  314. <xsl:value-of select="&primary;"/>
  315. <xsl:if test="@significance='preferred'"><xsl:value-of select="$significant.flag"/></xsl:if>
  316. <xsl:if test="secondary">
  317. <xsl:text>, </xsl:text>
  318. <xsl:value-of select="&secondary;"/>
  319. </xsl:if>
  320. <xsl:if test="tertiary">
  321. <xsl:text>, </xsl:text>
  322. <xsl:value-of select="&tertiary;"/>
  323. </xsl:if>
  324. </xsl:attribute>
  325. </rx:begin-index-range>
  326. </xsl:when>
  327. <xsl:otherwise>
  328. <xsl:call-template name="indexterm"/>
  329. </xsl:otherwise>
  330. </xsl:choose>
  331. </xsl:template>
  332. <xsl:template match="indexterm[@class='endofrange']">
  333. <xsl:choose>
  334. <xsl:when test="$xep.extensions != 0">
  335. <rx:end-index-range>
  336. <xsl:attribute name="ref-id">
  337. <xsl:value-of select="@startref"/>
  338. </xsl:attribute>
  339. </rx:end-index-range>
  340. </xsl:when>
  341. <xsl:otherwise>
  342. <xsl:call-template name="indexterm"/>
  343. </xsl:otherwise>
  344. </xsl:choose>
  345. </xsl:template>
  346. <!-- ==================================================================== -->
  347. <xsl:template match="indexentry">
  348. <fo:block>
  349. <!-- don't process 'seeie's from here -->
  350. <xsl:apply-templates select="primaryie|secondaryie|tertiaryie|seealsoie"/>
  351. </fo:block>
  352. </xsl:template>
  353. <xsl:template match="primaryie">
  354. <fo:block>
  355. <xsl:apply-templates/>
  356. <xsl:if test="following-sibling::seeie">
  357. <xsl:text> (</xsl:text>
  358. <xsl:call-template name="gentext">
  359. <xsl:with-param name="key" select="'see'"/>
  360. </xsl:call-template>
  361. <xsl:text> </xsl:text>
  362. <xsl:apply-templates select="following-sibling::seeie"/>
  363. <xsl:text>)</xsl:text>
  364. </xsl:if>
  365. </fo:block>
  366. </xsl:template>
  367. <xsl:template match="secondaryie">
  368. <fo:block start-indent="1pc">
  369. <xsl:apply-templates/>
  370. <xsl:if test="following-sibling::seeie">
  371. <xsl:text> (</xsl:text>
  372. <xsl:call-template name="gentext">
  373. <xsl:with-param name="key" select="'see'"/>
  374. </xsl:call-template>
  375. <xsl:text> </xsl:text>
  376. <xsl:apply-templates select="following-sibling::seeie"/>
  377. <xsl:text>)</xsl:text>
  378. </xsl:if>
  379. </fo:block>
  380. </xsl:template>
  381. <xsl:template match="tertiaryie">
  382. <fo:block start-indent="2pc">
  383. <xsl:apply-templates/>
  384. <xsl:if test="following-sibling::seeie">
  385. <xsl:text> (</xsl:text>
  386. <xsl:call-template name="gentext">
  387. <xsl:with-param name="key" select="'see'"/>
  388. </xsl:call-template>
  389. <xsl:text> </xsl:text>
  390. <xsl:apply-templates select="following-sibling::seeie"/>
  391. <xsl:text>)</xsl:text>
  392. </xsl:if>
  393. </fo:block>
  394. </xsl:template>
  395. <xsl:template match="seeie">
  396. <fo:inline>
  397. <xsl:apply-templates/>
  398. </fo:inline>
  399. </xsl:template>
  400. <xsl:template match="seealsoie">
  401. <fo:block>
  402. <xsl:attribute name="start-indent">
  403. <xsl:choose>
  404. <xsl:when test="(preceding-sibling::tertiaryie |
  405. preceding-sibling::secondaryie)[last()]
  406. [self::tertiaryie]">3pc</xsl:when>
  407. <xsl:when test="(preceding-sibling::tertiaryie |
  408. preceding-sibling::secondaryie)[last()]
  409. [self::secondaryie]">2pc</xsl:when>
  410. <xsl:otherwise>1pc</xsl:otherwise>
  411. </xsl:choose>
  412. </xsl:attribute>
  413. <xsl:text>(</xsl:text>
  414. <xsl:call-template name="gentext">
  415. <xsl:with-param name="key" select="'seealso'"/>
  416. </xsl:call-template>
  417. <xsl:text> </xsl:text>
  418. <xsl:apply-templates/>
  419. <xsl:text>)</xsl:text>
  420. </fo:block>
  421. </xsl:template>
  422. <!-- Determines if an object should be inserted as an fo:inline
  423. or an fo:block. Used for indexterms -->
  424. <xsl:template name="inline.or.block">
  425. <xsl:param name="parentnode" select=".."/>
  426. <xsl:variable name="parent" select="concat('|', local-name($parentnode), '|')"/>
  427. <xsl:variable name="block.parents" select="'|answer|appendix|appendixinfo|article|articleinfo|bibliodiv|bibliography|bibliographyinfo|blockinfo|blockquote|bookinfo|callout|caution|chapter|chapterinfo|dedication|example|figure|formalpara|funcsynopsisinfo|glossary|glossaryinfo|glossdef|glossdiv|glossentry|highlights|important|index|indexinfo|info|informalexample|informalfigure|informaltable|itemizedlist|legalnotice|listitem|msgexplan|msgtext|note|objectinfo|orderedlist|partinfo|partintro|preface|prefaceinfo|procedure|qandadiv|qandaset|question|refentry|refentryinfo|referenceinfo|refmeta|refmiscinfo|refsect1|refsect1info|refsect2|refsect2info|refsect3|refsect3info|refsection|refsectioninfo|refsynopsisdiv|refsynopsisdivinfo|revdescription|screeninfo|sect1|sect1info|sect2|sect2info|sect3|sect3info|sect4|sect4info|sect5|sect5info|section|sectioninfo|setindex|setindexinfo|setinfo|sidebar|sidebarinfo|simplesect|step|table|task|taskprerequisites|taskrelated|tasksummary|tip|topic|variablelist|warning|'"/>
  428. <xsl:choose>
  429. <xsl:when test="contains($block.parents, $parent)">fo:block</xsl:when>
  430. <xsl:when test="$fop1.extensions != 0">fo:wrapper</xsl:when>
  431. <xsl:otherwise>fo:inline</xsl:otherwise>
  432. </xsl:choose>
  433. </xsl:template>
  434. </xsl:stylesheet>