Problem: Counting recursive elements

walexand

Usenet Archive
Joined
Aug 9, 2004
Messages
3
Reaction score
0
I have mistake by counting a recursive element. Can someone help me.

XML Sample File
<content>
<section>
<title>index1</title>
<section>
<title>index11</title>
<section>
<title>index111</title>
<section>
<title>index1111</title>
<section>
<title>index11111</title>
<section>
<title>index11111</title>
</section>
</section>
</section>
</section>
</section>
</section>
</content>

My XSLT File
<xsl:template match="section" mode="content">
<xsl:variable name="level" select="count(./parent::section)+1" /> <xsl:element name="h{$level}"> <xsl:value-of select="title" /> </xsl:element> <xsl:if test="./section"> <xsl:apply-templates select="section" mode="full"/> </xsl:if> </xsl:template> I want to count automatic an index from the element "title",
To get this:

<h1>...
<h2>...
<h3>...
<h4>...
<h5>...
<h6>...

but my current Output looks like this
<h1>index1</h1>
<h2>index11</h2>
<h2>index111</h2>
<h2>index1111</h2>
<h2>index11111</h2>
<h2>index11111</h2>
 

Tuija Sonkkila

Usenet Archive
Joined
Oct 15, 2001
Messages
128
Reaction score
0
<xsl:variable name="level" select="count(./parent::section)+1" />

There's only one parent for each section. Instead, count sections in the ancestor-or-self axis.

Tuija
 

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

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top