maketoc.xsl 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  3. version="1.0"
  4. exclude-result-prefixes="doc">
  5. <!-- ********************************************************************
  6. $Id: maketoc.xsl 6910 2007-06-28 23:23:30Z xmldoc $
  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:import href="docbook.xsl"/>
  14. <xsl:import href="chunk.xsl"/>
  15. <xsl:output method="xml" indent="no" encoding='utf-8'/>
  16. <xsl:param name="toc.list.type" select="'tocentry'"/>
  17. <!-- refentry in autotoc.xsl does not use subtoc, so must
  18. handle it explicitly here. -->
  19. <xsl:template match="refentry" mode="toc">
  20. <xsl:param name="toc-context" select="."/>
  21. <xsl:call-template name="subtoc">
  22. <xsl:with-param name="toc-context" select="$toc-context"/>
  23. </xsl:call-template>
  24. </xsl:template>
  25. <xsl:template name="subtoc">
  26. <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
  27. <xsl:variable name="filename">
  28. <xsl:apply-templates select="." mode="chunk-filename"/>
  29. </xsl:variable>
  30. <xsl:variable name="chunk">
  31. <xsl:call-template name="chunk"/>
  32. </xsl:variable>
  33. <xsl:if test="$chunk != 0">
  34. <xsl:call-template name="indent-spaces"/>
  35. <xsl:variable name="id">
  36. <xsl:call-template name="object.id"/>
  37. </xsl:variable>
  38. <tocentry linkend="{$id}">
  39. <xsl:processing-instruction name="dbhtml">
  40. <xsl:text>filename="</xsl:text>
  41. <xsl:value-of select="$filename"/>
  42. <xsl:text>"</xsl:text>
  43. </xsl:processing-instruction>
  44. <xsl:text>&#xA;</xsl:text>
  45. <xsl:apply-templates mode="toc" select="$nodes"/>
  46. <xsl:call-template name="indent-spaces"/>
  47. </tocentry>
  48. <xsl:text>&#xA;</xsl:text>
  49. </xsl:if>
  50. </xsl:template>
  51. <xsl:template name="indent-spaces">
  52. <xsl:param name="node" select="."/>
  53. <xsl:text> </xsl:text>
  54. <xsl:if test="$node/parent::*">
  55. <xsl:call-template name="indent-spaces">
  56. <xsl:with-param name="node" select="$node/parent::*"/>
  57. </xsl:call-template>
  58. </xsl:if>
  59. </xsl:template>
  60. <!-- ==================================================================== -->
  61. <xsl:template match="/" priority="-1">
  62. <xsl:text>&#xA;</xsl:text>
  63. <toc role="chunk-toc">
  64. <xsl:text>&#xA;</xsl:text>
  65. <xsl:apply-templates select="/" mode="toc"/>
  66. </toc>
  67. <xsl:text>&#xA;</xsl:text>
  68. </xsl:template>
  69. </xsl:stylesheet>