index.xsl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?xml version='1.0'?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY primary 'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
  4. <!ENTITY secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas)]))'>
  5. <!ENTITY tertiary 'normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas)]))'>
  6. ]>
  7. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  9. xmlns:rx="http://www.renderx.com/XSL/Extensions"
  10. version='1.0'>
  11. <!-- ********************************************************************
  12. $Id$
  13. ********************************************************************
  14. This file is part of the XSL DocBook Stylesheet distribution.
  15. See ../README or http://docbook.sf.net/release/xsl/current/ for
  16. copyright and other information.
  17. ******************************************************************** -->
  18. <!-- ==================================================================== -->
  19. <xsl:template match="index">
  20. <xsl:variable name="id">
  21. <xsl:call-template name="object.id"/>
  22. </xsl:variable>
  23. <xsl:if test="$generate.index != 0">
  24. <xsl:choose>
  25. <xsl:when test="$make.index.markup != 0">
  26. <fo:block>
  27. <xsl:call-template name="generate-index-markup">
  28. <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
  29. </xsl:call-template>
  30. </fo:block>
  31. </xsl:when>
  32. <xsl:otherwise>
  33. <fo:block id="{$id}">
  34. <xsl:call-template name="index.titlepage"/>
  35. </fo:block>
  36. <xsl:apply-templates/>
  37. <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
  38. <xsl:call-template name="generate-index">
  39. <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
  40. </xsl:call-template>
  41. </xsl:if>
  42. </xsl:otherwise>
  43. </xsl:choose>
  44. </xsl:if>
  45. </xsl:template>
  46. <xsl:template match="book/index|part/index">
  47. <xsl:variable name="id">
  48. <xsl:call-template name="object.id"/>
  49. </xsl:variable>
  50. <xsl:if test="$generate.index != 0">
  51. <xsl:variable name="master-reference">
  52. <xsl:call-template name="select.pagemaster">
  53. <xsl:with-param name="pageclass">
  54. <xsl:if test="$make.index.markup != 0">body</xsl:if>
  55. </xsl:with-param>
  56. </xsl:call-template>
  57. </xsl:variable>
  58. <fo:page-sequence hyphenate="{$hyphenate}"
  59. master-reference="{$master-reference}">
  60. <xsl:attribute name="language">
  61. <xsl:call-template name="l10n.language"/>
  62. </xsl:attribute>
  63. <xsl:attribute name="format">
  64. <xsl:call-template name="page.number.format">
  65. <xsl:with-param name="master-reference" select="$master-reference"/>
  66. </xsl:call-template>
  67. </xsl:attribute>
  68. <xsl:attribute name="initial-page-number">
  69. <xsl:call-template name="initial.page.number">
  70. <xsl:with-param name="master-reference" select="$master-reference"/>
  71. </xsl:call-template>
  72. </xsl:attribute>
  73. <xsl:attribute name="force-page-count">
  74. <xsl:call-template name="force.page.count">
  75. <xsl:with-param name="master-reference" select="$master-reference"/>
  76. </xsl:call-template>
  77. </xsl:attribute>
  78. <xsl:attribute name="hyphenation-character">
  79. <xsl:call-template name="gentext">
  80. <xsl:with-param name="key" select="'hyphenation-character'"/>
  81. </xsl:call-template>
  82. </xsl:attribute>
  83. <xsl:attribute name="hyphenation-push-character-count">
  84. <xsl:call-template name="gentext">
  85. <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
  86. </xsl:call-template>
  87. </xsl:attribute>
  88. <xsl:attribute name="hyphenation-remain-character-count">
  89. <xsl:call-template name="gentext">
  90. <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
  91. </xsl:call-template>
  92. </xsl:attribute>
  93. <xsl:apply-templates select="." mode="running.head.mode">
  94. <xsl:with-param name="master-reference" select="$master-reference"/>
  95. </xsl:apply-templates>
  96. <xsl:apply-templates select="." mode="running.foot.mode">
  97. <xsl:with-param name="master-reference" select="$master-reference"/>
  98. </xsl:apply-templates>
  99. <fo:flow flow-name="xsl-region-body">
  100. <xsl:call-template name="set.flow.properties">
  101. <xsl:with-param name="element" select="local-name(.)"/>
  102. <xsl:with-param name="master-reference" select="$master-reference"/>
  103. </xsl:call-template>
  104. <fo:block id="{$id}">
  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">
  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">3pc</xsl:when>
  405. <xsl:when test="preceding-sibling::secondaryie">2pc</xsl:when>
  406. <xsl:otherwise>1pc</xsl:otherwise>
  407. </xsl:choose>
  408. </xsl:attribute>
  409. <xsl:text>(</xsl:text>
  410. <xsl:call-template name="gentext">
  411. <xsl:with-param name="key" select="'seealso'"/>
  412. </xsl:call-template>
  413. <xsl:text> </xsl:text>
  414. <xsl:apply-templates/>
  415. <xsl:text>)</xsl:text>
  416. </fo:block>
  417. </xsl:template>
  418. <!-- Determines if an object should be inserted as an fo:inline
  419. or an fo:block. Used for indexterms -->
  420. <xsl:template name="inline.or.block">
  421. <xsl:param name="parentnode" select=".."/>
  422. <xsl:variable name="parent" select="local-name($parentnode)"/>
  423. <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|variablelist|warning|'"/>
  424. <xsl:choose>
  425. <xsl:when test="contains($parent, $block.parents)">fo:block</xsl:when>
  426. <xsl:otherwise>fo:inline</xsl:otherwise>
  427. </xsl:choose>
  428. </xsl:template>
  429. </xsl:stylesheet>