toc.xsl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?xml version="1.0" encoding="ASCII"?>
  2. <!--This file was created automatically by html2xhtml-->
  3. <!--from the HTML stylesheets.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
  5. <!-- ********************************************************************
  6. $Id$
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. ******************************************************************** -->
  12. <!-- ==================================================================== -->
  13. <xsl:template match="toc">
  14. <xsl:choose>
  15. <xsl:when test="*">
  16. <xsl:if test="$process.source.toc != 0">
  17. <!-- if the toc isn't empty, process it -->
  18. <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
  19. <xsl:apply-templates/>
  20. </xsl:element>
  21. </xsl:if>
  22. </xsl:when>
  23. <xsl:otherwise>
  24. <xsl:if test="$process.empty.source.toc != 0">
  25. <xsl:choose>
  26. <xsl:when test="parent::section or parent::sect1 or parent::sect2 or parent::sect3 or parent::sect4 or parent::sect5">
  27. <xsl:apply-templates select="parent::*" mode="toc.for.section"/>
  28. </xsl:when>
  29. <xsl:when test="parent::article">
  30. <xsl:apply-templates select="parent::*" mode="toc.for.component"/>
  31. </xsl:when>
  32. <xsl:when test="parent::book or parent::part">
  33. <xsl:apply-templates select="parent::*" mode="toc.for.division"/>
  34. </xsl:when>
  35. <xsl:when test="parent::set">
  36. <xsl:apply-templates select="parent::*" mode="toc.for.set"/>
  37. </xsl:when>
  38. <!-- there aren't any other contexts that allow toc -->
  39. <xsl:otherwise>
  40. <xsl:message>
  41. <xsl:text>I don't know how to make a TOC in this context!</xsl:text>
  42. </xsl:message>
  43. </xsl:otherwise>
  44. </xsl:choose>
  45. </xsl:if>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. </xsl:template>
  49. <xsl:template match="tocpart|tocchap |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  50. <xsl:variable name="sub-toc">
  51. <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  52. <xsl:choose>
  53. <xsl:when test="$toc.list.type = 'dl'">
  54. <dd>
  55. <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
  56. <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
  57. </xsl:element>
  58. </dd>
  59. </xsl:when>
  60. <xsl:otherwise>
  61. <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
  62. <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
  63. </xsl:element>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:if>
  67. </xsl:variable>
  68. <xsl:apply-templates select="tocentry[position() != last()]"/>
  69. <xsl:choose>
  70. <xsl:when test="$toc.list.type = 'dl'">
  71. <dt>
  72. <xsl:apply-templates select="tocentry[position() = last()]"/>
  73. </dt>
  74. <xsl:copy-of select="$sub-toc"/>
  75. </xsl:when>
  76. <xsl:otherwise>
  77. <li>
  78. <xsl:apply-templates select="tocentry[position() = last()]"/>
  79. <xsl:copy-of select="$sub-toc"/>
  80. </li>
  81. </xsl:otherwise>
  82. </xsl:choose>
  83. </xsl:template>
  84. <xsl:template match="tocentry|tocfront|tocback">
  85. <xsl:choose>
  86. <xsl:when test="$toc.list.type = 'dl'">
  87. <dt>
  88. <xsl:call-template name="tocentry-content"/>
  89. </dt>
  90. </xsl:when>
  91. <xsl:otherwise>
  92. <li>
  93. <xsl:call-template name="tocentry-content"/>
  94. </li>
  95. </xsl:otherwise>
  96. </xsl:choose>
  97. </xsl:template>
  98. <xsl:template match="tocentry[position() = last()]" priority="2">
  99. <xsl:call-template name="tocentry-content"/>
  100. </xsl:template>
  101. <xsl:template name="tocentry-content">
  102. <xsl:variable name="targets" select="key('id',@linkend)"/>
  103. <xsl:variable name="target" select="$targets[1]"/>
  104. <xsl:choose>
  105. <xsl:when test="@linkend">
  106. <xsl:call-template name="check.id.unique">
  107. <xsl:with-param name="linkend" select="@linkend"/>
  108. </xsl:call-template>
  109. <a>
  110. <xsl:attribute name="href">
  111. <xsl:call-template name="href.target">
  112. <xsl:with-param name="object" select="$target"/>
  113. </xsl:call-template>
  114. </xsl:attribute>
  115. <xsl:apply-templates/>
  116. </a>
  117. </xsl:when>
  118. <xsl:otherwise>
  119. <xsl:apply-templates/>
  120. </xsl:otherwise>
  121. </xsl:choose>
  122. </xsl:template>
  123. <!-- ==================================================================== -->
  124. <xsl:template match="*" mode="toc.for.section">
  125. <xsl:call-template name="section.toc"/>
  126. </xsl:template>
  127. <xsl:template match="*" mode="toc.for.component">
  128. <xsl:call-template name="component.toc"/>
  129. </xsl:template>
  130. <xsl:template match="*" mode="toc.for.section">
  131. <xsl:call-template name="section.toc"/>
  132. </xsl:template>
  133. <xsl:template match="*" mode="toc.for.division">
  134. <xsl:call-template name="division.toc"/>
  135. </xsl:template>
  136. <xsl:template match="*" mode="toc.for.set">
  137. <xsl:call-template name="set.toc"/>
  138. </xsl:template>
  139. <!-- ==================================================================== -->
  140. <xsl:template match="lot|lotentry">
  141. </xsl:template>
  142. </xsl:stylesheet>