index.xsl 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. version='1.0'>
  4. <!-- ********************************************************************
  5. $Id: index.xsl 9297 2012-04-22 03:56:16Z bobstayton $
  6. ********************************************************************
  7. This file is part of the XSL DocBook Stylesheet distribution.
  8. See ../README or http://docbook.sf.net/release/xsl/current/ for
  9. copyright and other information.
  10. ******************************************************************** -->
  11. <!-- ==================================================================== -->
  12. <xsl:template match="index">
  13. <!-- some implementations use completely empty index tags to indicate -->
  14. <!-- where an automatically generated index should be inserted. so -->
  15. <!-- if the index is completely empty, skip it. Unless generate.index -->
  16. <!-- is non-zero, in which case, this is where the automatically -->
  17. <!-- generated index should go. -->
  18. <xsl:call-template name="id.warning"/>
  19. <xsl:if test="count(*)>0 or $generate.index != '0'">
  20. <div>
  21. <xsl:apply-templates select="." mode="common.html.attributes"/>
  22. <xsl:call-template name="id.attribute">
  23. <xsl:with-param name="conditional" select="0"/>
  24. </xsl:call-template>
  25. <xsl:call-template name="index.titlepage"/>
  26. <xsl:choose>
  27. <xsl:when test="indexdiv">
  28. <xsl:apply-templates/>
  29. </xsl:when>
  30. <xsl:otherwise>
  31. <xsl:apply-templates select="*[not(self::indexentry)]"/>
  32. <!-- Because it's actually valid for Index to have neither any -->
  33. <!-- Indexdivs nor any Indexentries, we need to check and make -->
  34. <!-- sure that at least one Indexentry exists, and generate a -->
  35. <!-- wrapper dl if there is at least one; otherwise, do nothing. -->
  36. <xsl:if test="indexentry">
  37. <!-- The indexentry template assumes a parent dl wrapper has -->
  38. <!-- been generated; for Indexes that have Indexdivs, the dl -->
  39. <!-- wrapper is generated by the indexdiv template; however, -->
  40. <!-- for Indexes that lack Indexdivs, if we don't generate a -->
  41. <!-- dl here, HTML output will not be valid. -->
  42. <dl>
  43. <xsl:apply-templates select="indexentry"/>
  44. </dl>
  45. </xsl:if>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
  49. <xsl:call-template name="generate-index">
  50. <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
  51. </xsl:call-template>
  52. </xsl:if>
  53. <xsl:if test="not(parent::article)">
  54. <xsl:call-template name="process.footnotes"/>
  55. </xsl:if>
  56. </div>
  57. </xsl:if>
  58. </xsl:template>
  59. <xsl:template match="setindex">
  60. <!-- some implementations use completely empty index tags to indicate -->
  61. <!-- where an automatically generated index should be inserted. so -->
  62. <!-- if the index is completely empty, skip it. Unless generate.index -->
  63. <!-- is non-zero, in which case, this is where the automatically -->
  64. <!-- generated index should go. -->
  65. <xsl:call-template name="id.warning"/>
  66. <xsl:if test="count(*)>0 or $generate.index != '0'">
  67. <div>
  68. <xsl:apply-templates select="." mode="common.html.attributes"/>
  69. <xsl:call-template name="id.attribute">
  70. <xsl:with-param name="conditional" select="0"/>
  71. </xsl:call-template>
  72. <xsl:call-template name="setindex.titlepage"/>
  73. <xsl:apply-templates/>
  74. <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
  75. <xsl:call-template name="generate-index">
  76. <xsl:with-param name="scope" select="/"/>
  77. </xsl:call-template>
  78. </xsl:if>
  79. <xsl:if test="not(parent::article)">
  80. <xsl:call-template name="process.footnotes"/>
  81. </xsl:if>
  82. </div>
  83. </xsl:if>
  84. </xsl:template>
  85. <xsl:template match="index/indexinfo"></xsl:template>
  86. <xsl:template match="index/info"></xsl:template>
  87. <xsl:template match="index/title"></xsl:template>
  88. <xsl:template match="index/subtitle"></xsl:template>
  89. <xsl:template match="index/titleabbrev"></xsl:template>
  90. <!-- ==================================================================== -->
  91. <xsl:template match="indexdiv">
  92. <xsl:call-template name="id.warning"/>
  93. <div>
  94. <xsl:apply-templates select="." mode="common.html.attributes"/>
  95. <xsl:call-template name="id.attribute"/>
  96. <xsl:call-template name="anchor"/>
  97. <xsl:apply-templates select="*[not(self::indexentry)]"/>
  98. <dl>
  99. <xsl:apply-templates select="indexentry"/>
  100. </dl>
  101. </div>
  102. </xsl:template>
  103. <xsl:template match="indexdiv/title">
  104. <h3>
  105. <xsl:apply-templates select="." mode="common.html.attributes"/>
  106. <xsl:apply-templates/>
  107. </h3>
  108. </xsl:template>
  109. <!-- ==================================================================== -->
  110. <xsl:template match="indexterm">
  111. <!-- this one must have a name, even if it doesn't have an ID -->
  112. <xsl:variable name="id">
  113. <xsl:call-template name="object.id"/>
  114. </xsl:variable>
  115. <a class="indexterm" name="{$id}"/>
  116. </xsl:template>
  117. <xsl:template match="primary|secondary|tertiary|see|seealso">
  118. </xsl:template>
  119. <!-- ==================================================================== -->
  120. <xsl:template match="indexentry">
  121. <xsl:apply-templates select="primaryie"/>
  122. </xsl:template>
  123. <xsl:template match="primaryie">
  124. <dt>
  125. <xsl:apply-templates/>
  126. </dt>
  127. <dd>
  128. <xsl:apply-templates select="following-sibling::seeie
  129. [not(preceding-sibling::secondaryie)]"
  130. mode="indexentry"/>
  131. <xsl:apply-templates select="following-sibling::seealsoie
  132. [not(preceding-sibling::secondaryie)]"
  133. mode="indexentry"/>
  134. <xsl:apply-templates select="following-sibling::secondaryie"
  135. mode="indexentry"/>
  136. </dd>
  137. </xsl:template>
  138. <!-- Handled in mode to convert flat list to structured output -->
  139. <xsl:template match="secondaryie">
  140. </xsl:template>
  141. <xsl:template match="tertiaryie">
  142. </xsl:template>
  143. <xsl:template match="seeie|seealsoie">
  144. </xsl:template>
  145. <xsl:template match="secondaryie" mode="indexentry">
  146. <dl>
  147. <dt>
  148. <xsl:apply-templates/>
  149. </dt>
  150. <dd>
  151. <!-- select following see* elements up to next secondaryie or tertiary or end -->
  152. <xsl:variable name="after.this"
  153. select="following-sibling::*"/>
  154. <xsl:variable name="next.entry"
  155. select="(following-sibling::secondaryie|following-sibling::tertiaryie)[1]"/>
  156. <xsl:variable name="before.entry"
  157. select="$next.entry/preceding-sibling::*"/>
  158. <xsl:variable name="see.intersection"
  159. select="$after.this[count(.|$before.entry) = count($before.entry)]
  160. [self::seeie or self::seealsoie]"/>
  161. <xsl:choose>
  162. <xsl:when test="count($see.intersection) != 0">
  163. <xsl:apply-templates select="$see.intersection" mode="indexentry"/>
  164. </xsl:when>
  165. <xsl:when test="count($next.entry) = 0">
  166. <xsl:apply-templates select="following-sibling::seeie"
  167. mode="indexentry"/>
  168. <xsl:apply-templates select="following-sibling::seealsoie"
  169. mode="indexentry"/>
  170. </xsl:when>
  171. </xsl:choose>
  172. <!-- now process any tertiaryie before the next secondaryie -->
  173. <xsl:variable name="before.next.secondary"
  174. select="following-sibling::secondaryie[1]/preceding-sibling::*"/>
  175. <xsl:variable name="tertiary.intersection"
  176. select="$after.this[count(.|$before.next.secondary) =
  177. count($before.next.secondary)]
  178. [not(self::seeie) and not(self::seealsoie)]"/>
  179. <xsl:choose>
  180. <xsl:when test="count($tertiary.intersection) != 0">
  181. <xsl:apply-templates select="$tertiary.intersection"
  182. mode="indexentry"/>
  183. </xsl:when>
  184. <xsl:when test="not(following-sibling::secondaryie)">
  185. <xsl:apply-templates select="following-sibling::tertiaryie"
  186. mode="indexentry"/>
  187. </xsl:when>
  188. </xsl:choose>
  189. </dd>
  190. </dl>
  191. </xsl:template>
  192. <xsl:template match="tertiaryie" mode="indexentry">
  193. <dl>
  194. <dt>
  195. <xsl:apply-templates/>
  196. </dt>
  197. <dd>
  198. <!-- select following see* elements up to next secondaryie or tertiary or end -->
  199. <xsl:variable name="after.this"
  200. select="following-sibling::*"/>
  201. <xsl:variable name="next.entry"
  202. select="(following-sibling::secondaryie|following-sibling::tertiaryie)[1]"/>
  203. <xsl:variable name="before.entry"
  204. select="$next.entry/preceding-sibling::*"/>
  205. <xsl:variable name="see.intersection"
  206. select="$after.this[count(.|$before.entry) = count($before.entry)]
  207. [self::seeie or self::seealsoie]"/>
  208. <xsl:choose>
  209. <xsl:when test="count($see.intersection) != 0">
  210. <xsl:apply-templates select="$see.intersection" mode="indexentry"/>
  211. </xsl:when>
  212. <xsl:when test="count($next.entry) = 0">
  213. <xsl:apply-templates select="following-sibling::seeie"
  214. mode="indexentry"/>
  215. <xsl:apply-templates select="following-sibling::seealsoie"
  216. mode="indexentry"/>
  217. </xsl:when>
  218. </xsl:choose>
  219. </dd>
  220. </dl>
  221. </xsl:template>
  222. <xsl:template match="seeie" mode="indexentry">
  223. <dt>
  224. <xsl:text>(</xsl:text>
  225. <xsl:call-template name="gentext">
  226. <xsl:with-param name="key" select="'see'"/>
  227. </xsl:call-template>
  228. <xsl:text> </xsl:text>
  229. <xsl:apply-templates/>
  230. <xsl:text>)</xsl:text>
  231. </dt>
  232. </xsl:template>
  233. <xsl:template match="seealsoie" mode="indexentry">
  234. <div>
  235. <xsl:text>(</xsl:text>
  236. <xsl:call-template name="gentext">
  237. <xsl:with-param name="key" select="'seealso'"/>
  238. </xsl:call-template>
  239. <xsl:text> </xsl:text>
  240. <xsl:apply-templates/>
  241. <xsl:text>)</xsl:text>
  242. </div>
  243. </xsl:template>
  244. </xsl:stylesheet>