XSLT Table of Contens

W

walexand

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. ([email protected])
 
?

=?ISO-8859-1?Q?R=E9mi_Peyronnet?=

(e-mail address removed) 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top