lfs-toc.xsl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <!-- Version 0.9 - Manuel Canales Esparcia <macana@lfs-es.org> -->
  3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns="http://www.w3.org/1999/xhtml"
  5. version="1.0">
  6. <!-- General settings -->
  7. <xsl:param name="generate.toc">
  8. appendix toc
  9. book toc,title,figure,table,example,equation
  10. chapter nop
  11. part toc
  12. preface nop
  13. qandadiv nop
  14. qandaset nop
  15. reference nop
  16. sect1 nop
  17. sect2 nop
  18. sect3 nop
  19. sect4 nop
  20. sect5 nop
  21. section nop
  22. set nop
  23. </xsl:param>
  24. <xsl:param name="toc.section.depth">1</xsl:param>
  25. <xsl:param name="toc.max.depth">3</xsl:param>
  26. <!-- Making the TOC -->
  27. <xsl:template name="make.toc">
  28. <xsl:param name="toc-context" select="."/>
  29. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  30. <xsl:if test="$nodes">
  31. <div class="toc">
  32. <h3>
  33. <xsl:call-template name="gentext">
  34. <xsl:with-param name="key">TableofContents</xsl:with-param>
  35. </xsl:call-template>
  36. </h3>
  37. <ul>
  38. <xsl:apply-templates select="$nodes" mode="toc">
  39. <xsl:with-param name="toc-context" select="$toc-context"/>
  40. </xsl:apply-templates>
  41. </ul>
  42. </div>
  43. </xsl:if>
  44. </xsl:template>
  45. <!-- Making the subtocs -->
  46. <xsl:template name="subtoc">
  47. <xsl:param name="toc-context" select="."/>
  48. <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
  49. <xsl:variable name="subtoc">
  50. <ul>
  51. <xsl:apply-templates mode="toc" select="$nodes">
  52. <xsl:with-param name="toc-context" select="$toc-context"/>
  53. </xsl:apply-templates>
  54. </ul>
  55. </xsl:variable>
  56. <xsl:variable name="depth">
  57. <xsl:choose>
  58. <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
  59. <xsl:otherwise>0</xsl:otherwise>
  60. </xsl:choose>
  61. </xsl:variable>
  62. <xsl:variable name="depth.from.context"
  63. select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
  64. <li class="{name(.)}">
  65. <xsl:call-template name="toc.line">
  66. <xsl:with-param name="toc-context" select="$toc-context"/>
  67. </xsl:call-template>
  68. <xsl:if test="$toc.section.depth &gt; $depth and count($nodes)&gt;0
  69. and $toc.max.depth &gt; $depth.from.context">
  70. <xsl:copy-of select="$subtoc"/>
  71. </xsl:if>
  72. </li>
  73. </xsl:template>
  74. <!--Adding the h* tags and dropping redundats links-->
  75. <xsl:template name="toc.line">
  76. <xsl:param name="toc-context" select="."/>
  77. <xsl:param name="depth" select="1"/>
  78. <xsl:param name="depth.from.context" select="8"/>
  79. <xsl:choose>
  80. <xsl:when test="local-name(.) = 'sect1'">
  81. <a>
  82. <xsl:attribute name="href">
  83. <xsl:call-template name="href.target">
  84. <xsl:with-param name="context" select="$toc-context"/>
  85. </xsl:call-template>
  86. </xsl:attribute>
  87. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  88. </a>
  89. </xsl:when>
  90. <xsl:when test="local-name(.) = 'chapter' or local-name(.) = 'preface'">
  91. <h4>
  92. <xsl:variable name="label">
  93. <xsl:apply-templates select="." mode="label.markup"/>
  94. </xsl:variable>
  95. <xsl:copy-of select="$label"/>
  96. <xsl:if test="$label != ''">
  97. <xsl:value-of select="$autotoc.label.separator"/>
  98. </xsl:if>
  99. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  100. </h4>
  101. </xsl:when>
  102. <xsl:when test="local-name(.) = 'part'">
  103. <h3>
  104. <xsl:variable name="label">
  105. <xsl:apply-templates select="." mode="label.markup"/>
  106. </xsl:variable>
  107. <xsl:copy-of select="$label"/>
  108. <xsl:if test="$label != ''">
  109. <xsl:value-of select="$autotoc.label.separator"/>
  110. </xsl:if>
  111. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  112. </h3>
  113. </xsl:when>
  114. <xsl:otherwise>
  115. <h3>
  116. <a>
  117. <xsl:attribute name="href">
  118. <xsl:call-template name="href.target">
  119. <xsl:with-param name="context" select="$toc-context"/>
  120. </xsl:call-template>
  121. </xsl:attribute>
  122. <xsl:variable name="label">
  123. <xsl:apply-templates select="." mode="label.markup"/>
  124. </xsl:variable>
  125. <xsl:copy-of select="$label"/>
  126. <xsl:if test="$label != ''">
  127. <xsl:value-of select="$autotoc.label.separator"/>
  128. </xsl:if>
  129. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  130. </a>
  131. </h3>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. </xsl:template>
  135. </xsl:stylesheet>