lfs-toc.xsl 7.1 KB

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