how to get document headers using XSLT.

Roseanne Zhang

I spent sometime this weekend, and solved your problem. It was hard to me, but the answer is simple. :)

Here is your answer:
Q. How to use recursion to produce table of contents effect? Example here.

The XSLT, XML, and output are all there. I also fixed one discrepency between your XML and output you want.

The style sheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />
  <xsl:template match="/main">
    <xsl:value-of select="@title"/>
    <xsl:call-template name="p">
      <xsl:with-param name="prefix" select="'" />
      <xsl:with-param name="indent" select="'  '" />
  <xsl:template name="p" >
    <xsl:param name="prefix" />
    <xsl:param name="indent" />    
    <xsl:for-each select="section" >
      <xsl:value-of select="$indent"/>
      <xsl:value-of select="$prefix"/>
      <xsl:value-of select="position()"/>) <xsl:value-of select="@title" />
      <xsl:call-template name="p">
        <xsl:with-param name="prefix" select="concat($prefix, position(), '.')" />
        <xsl:with-param name="indent" select="concat($indent, '  ')" />