lfs-toc.xsl 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <!--
  3. $LastChangedBy$
  4. $Date$
  5. -->
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns="http://www.w3.org/1999/xhtml"
  8. version="1.0">
  9. <!-- This stylesheet controls how the TOC are generated -->
  10. <!-- make.toc:
  11. Using h3 for TOC title.
  12. Using ul for TOC list style.
  13. Removed code for $manual.toc and $qanda.in.toc -->
  14. <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  15. <xsl:template name="make.toc">
  16. <xsl:param name="toc-context" select="."/>
  17. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  18. <xsl:if test="$nodes">
  19. <div class="toc">
  20. <h3>
  21. <xsl:call-template name="gentext">
  22. <xsl:with-param name="key">TableofContents</xsl:with-param>
  23. </xsl:call-template>
  24. </h3>
  25. <ul>
  26. <xsl:apply-templates select="$nodes" mode="toc">
  27. <xsl:with-param name="toc-context" select="$toc-context"/>
  28. </xsl:apply-templates>
  29. </ul>
  30. </div>
  31. </xsl:if>
  32. </xsl:template>
  33. <!-- subtoc:
  34. Using ul for TOC list style.
  35. Removed code for $qanda.in.toc
  36. Removed code for sect* others than sect1 -->
  37. <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  38. <xsl:template name="subtoc">
  39. <xsl:param name="toc-context" select="."/>
  40. <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
  41. <xsl:variable name="subtoc">
  42. <ul>
  43. <xsl:apply-templates mode="toc" select="$nodes">
  44. <xsl:with-param name="toc-context" select="$toc-context"/>
  45. </xsl:apply-templates>
  46. </ul>
  47. </xsl:variable>
  48. <xsl:variable name="depth">
  49. <xsl:choose>
  50. <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
  51. <xsl:otherwise>0</xsl:otherwise>
  52. </xsl:choose>
  53. </xsl:variable>
  54. <xsl:variable name="depth.from.context"
  55. select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
  56. <li class="{name(.)}">
  57. <xsl:call-template name="toc.line">
  58. <xsl:with-param name="toc-context" select="$toc-context"/>
  59. </xsl:call-template>
  60. <xsl:if test="$toc.section.depth &gt; $depth and count($nodes)&gt;0
  61. and $toc.max.depth &gt; $depth.from.context">
  62. <xsl:copy-of select="$subtoc"/>
  63. </xsl:if>
  64. </li>
  65. </xsl:template>
  66. <!-- toc.line:
  67. Adding the h* tags and dropping unneded links.
  68. This template is a full re-made version of the original one. -->
  69. <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  70. <xsl:template name="toc.line">
  71. <xsl:param name="toc-context" select="."/>
  72. <xsl:choose>
  73. <!-- For non dummy sect1 targets, create a link. -->
  74. <xsl:when test="local-name(.) = 'sect1'">
  75. <xsl:choose>
  76. <xsl:when test="@role='dummy'">
  77. <span class="dummy">
  78. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  79. </span>
  80. </xsl:when>
  81. <xsl:otherwise>
  82. <a>
  83. <xsl:attribute name="href">
  84. <xsl:call-template name="href.target">
  85. <xsl:with-param name="context" select="$toc-context"/>
  86. </xsl:call-template>
  87. </xsl:attribute>
  88. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  89. </a>
  90. </xsl:otherwise>
  91. </xsl:choose>
  92. </xsl:when>
  93. <!-- For part, preface, and chapter, use hX and add the label.
  94. For BLFS, make it a link. -->
  95. <xsl:when test="local-name(.) = 'part' or local-name(.) = 'preface'
  96. or local-name(.) = 'chapter'">
  97. <xsl:choose>
  98. <xsl:when test="$book-type = 'blfs'">
  99. <xsl:apply-templates select="." mode="add.hX">
  100. <xsl:with-param name="toc-context" select="$toc-context"/>
  101. <xsl:with-param name="with-link" select="1"/>
  102. </xsl:apply-templates>
  103. </xsl:when>
  104. <xsl:otherwise>
  105. <xsl:apply-templates select="." mode="add.hX">
  106. <xsl:with-param name="toc-context" select="$toc-context"/>
  107. <xsl:with-param name="with-link" select="0"/>
  108. </xsl:apply-templates>
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. </xsl:when>
  112. <!-- For appendix , create a link and add the label.
  113. For BLFS, use hX. -->
  114. <xsl:when test="local-name(.) = 'appendix'">
  115. <xsl:choose>
  116. <xsl:when test="$book-type = 'blfs'">
  117. <xsl:apply-templates select="." mode="add.hX">
  118. <xsl:with-param name="toc-context" select="$toc-context"/>
  119. <xsl:with-param name="with-link" select="1"/>
  120. </xsl:apply-templates>
  121. </xsl:when>
  122. <xsl:otherwise>
  123. <xsl:apply-templates select="." mode="add.link">
  124. <xsl:with-param name="toc-context" select="$toc-context"/>
  125. </xsl:apply-templates>
  126. </xsl:otherwise>
  127. </xsl:choose>
  128. </xsl:when>
  129. <!-- For other targets like Index, use hX, create a link, and label it. -->
  130. <xsl:otherwise>
  131. <xsl:apply-templates select="." mode="add.hX">
  132. <xsl:with-param name="toc-context" select="$toc-context"/>
  133. <xsl:with-param name="with-link" select="1"/>
  134. </xsl:apply-templates>
  135. </xsl:otherwise>
  136. </xsl:choose>
  137. </xsl:template>
  138. <!-- Self-made template to add hX tags to toc lines. -->
  139. <xsl:template match="*" mode="add.hX">
  140. <xsl:param name="toc-context" select="."/>
  141. <xsl:param name="with-link" select="0"/>
  142. <xsl:param name="hlevel">
  143. <xsl:choose>
  144. <xsl:when test="local-name(.)='chapter' or local-name(.)='preface'">4</xsl:when>
  145. <xsl:otherwise>3</xsl:otherwise>
  146. </xsl:choose>
  147. </xsl:param>
  148. <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
  149. <xsl:choose>
  150. <xsl:when test="$with-link != 0">
  151. <xsl:apply-templates select="." mode="add.link">
  152. <xsl:with-param name="toc-context" select="$toc-context"/>
  153. </xsl:apply-templates>
  154. </xsl:when>
  155. <xsl:otherwise>
  156. <xsl:apply-templates select="." mode="label.and.title"/>
  157. </xsl:otherwise>
  158. </xsl:choose>
  159. </xsl:element>
  160. </xsl:template>
  161. <!-- Self-made template to made toc line a link. -->
  162. <xsl:template match="*" mode="add.link">
  163. <xsl:param name="toc-context" select="."/>
  164. <a>
  165. <xsl:attribute name="href">
  166. <xsl:call-template name="href.target">
  167. <xsl:with-param name="context" select="$toc-context"/>
  168. </xsl:call-template>
  169. </xsl:attribute>
  170. <xsl:apply-templates select="." mode="label.and.title"/>
  171. </a>
  172. </xsl:template>
  173. <!-- Self-made template to write the target title and label it. -->
  174. <xsl:template match="*" mode="label.and.title">
  175. <xsl:variable name="label">
  176. <xsl:apply-templates select="." mode="label.markup"/>
  177. </xsl:variable>
  178. <xsl:copy-of select="$label"/>
  179. <xsl:if test="$label != ''">
  180. <xsl:value-of select="$autotoc.label.separator"/>
  181. </xsl:if>
  182. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  183. </xsl:template>
  184. </xsl:stylesheet>