XSLT Table of Contens

Discussion in 'XML' started by walexand@web.de, Aug 9, 2004.

  1. Guest

    Can someone help me! I'am trying to develope a XSTL that make me
    automatic a "Table of Centens" from a XML Document.

    my XLM File looks like this:
    -------------------------------------
    <section>
    <title>Index1</title>
    </section>
    <section>
    <title>Index2</title>
    <section>
    <title>Index21</title>
    <section>
    <title>Index211</title>
    </section>
    </section>
    <section>
    <title>Index22</title>
    </section>
    </section>
    <section>
    <title>Index3</title>
    </section>
    -------------------------------------

    And a want to get this output:
    -------------------------------------
    <h2>Toc<h2>
    <ol>
    <li>Index1 </li>
    <li>Index2
    <ol>
    <li>Index21
    <ol>
    <li>Index211</li>
    </ol>
    </li>
    <li>Index22</li>
    </ol>
    </li>
    <li>Index3</li>
    </ol>


    Alexander W. ()
    , Aug 9, 2004
    #1
    1. Advertising

  2. a écrit :
    > Can someone help me! I'am trying to develope a XSTL that make me
    > automatic a "Table of Centens" from a XML Document.


    This should do it :

    <xsl:template match="/">
    <h2>Toc</h2>
    <ol>
    <xsl:apply-templates />
    </ol>
    </xsl:template>

    <xsl:template match="section">
    <li><xsl:apply-templates select="title" />
    <xsl:if test="count(section)&gt;0">
    <ol>
    <xsl:apply-templates select="section"/>
    </ol>
    </xsl:if>
    </li>
    </xsl:template>

    A good entry point about XSLT :
    http://www.zvon.org/xxl/XSLTutorial/Output/index.html

    Hth

    --
    Rémi Peyronnet
    =?ISO-8859-1?Q?R=E9mi_Peyronnet?=, Aug 9, 2004
    #2
    1. Advertising

  3. Guest

    Thanks Rémi Peyronnet! Works fine.
    , Aug 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,107
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Stylus Studio
    Replies:
    0
    Views:
    640
    Stylus Studio
    Aug 3, 2004
  3. Rio
    Replies:
    4
    Views:
    1,174
  4. Jeff

    how to select contens of div?

    Jeff, Jan 19, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    348
    Alexey Smirnov
    Jan 20, 2009
  5. Jeff
    Replies:
    6
    Views:
    1,164
    Göran Andersson
    Feb 18, 2009
Loading...

Share This Page