lfs-toc.xsl 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 redundats 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:param name="depth" select="1"/>
  69. <xsl:param name="depth.from.context" select="8"/>
  70. <xsl:choose>
  71. <!-- For sect1 targets, create a link -->
  72. <xsl:when test="local-name(.) = 'sect1'">
  73. <a>
  74. <xsl:attribute name="href">
  75. <xsl:call-template name="href.target">
  76. <xsl:with-param name="context" select="$toc-context"/>
  77. </xsl:call-template>
  78. </xsl:attribute>
  79. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  80. </a>
  81. </xsl:when>
  82. <!-- For appendix target, create a link and add the label -->
  83. <xsl:when test="local-name(.) = 'appendix'">
  84. <a>
  85. <xsl:attribute name="href">
  86. <xsl:call-template name="href.target">
  87. <xsl:with-param name="context" select="$toc-context"/>
  88. </xsl:call-template>
  89. </xsl:attribute>
  90. <xsl:variable name="label">
  91. <xsl:apply-templates select="." mode="label.markup"/>
  92. </xsl:variable>
  93. <xsl:copy-of select="$label"/>
  94. <xsl:if test="$label != ''">
  95. <xsl:value-of select="$autotoc.label.separator"/>
  96. </xsl:if>
  97. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  98. </a>
  99. </xsl:when>
  100. <!-- For chapter and preface, use h4 and add the label -->
  101. <xsl:when test="local-name(.) = 'chapter' or local-name(.) = 'preface'">
  102. <h4>
  103. <xsl:variable name="label">
  104. <xsl:apply-templates select="." mode="label.markup"/>
  105. </xsl:variable>
  106. <xsl:copy-of select="$label"/>
  107. <xsl:if test="$label != ''">
  108. <xsl:value-of select="$autotoc.label.separator"/>
  109. </xsl:if>
  110. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  111. </h4>
  112. </xsl:when>
  113. <!-- for part, use h3 and add the label -->
  114. <xsl:when test="local-name(.) = 'part'">
  115. <h3>
  116. <xsl:variable name="label">
  117. <xsl:apply-templates select="." mode="label.markup"/>
  118. </xsl:variable>
  119. <xsl:copy-of select="$label"/>
  120. <xsl:if test="$label != ''">
  121. <xsl:value-of select="$autotoc.label.separator"/>
  122. </xsl:if>
  123. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  124. </h3>
  125. </xsl:when>
  126. <!-- For other targets like Index, create a link inside h3 plus label it -->
  127. <xsl:otherwise>
  128. <h3>
  129. <a>
  130. <xsl:attribute name="href">
  131. <xsl:call-template name="href.target">
  132. <xsl:with-param name="context" select="$toc-context"/>
  133. </xsl:call-template>
  134. </xsl:attribute>
  135. <xsl:variable name="label">
  136. <xsl:apply-templates select="." mode="label.markup"/>
  137. </xsl:variable>
  138. <xsl:copy-of select="$label"/>
  139. <xsl:if test="$label != ''">
  140. <xsl:value-of select="$autotoc.label.separator"/>
  141. </xsl:if>
  142. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  143. </a>
  144. </h3>
  145. </xsl:otherwise>
  146. </xsl:choose>
  147. </xsl:template>
  148. </xsl:stylesheet>