Problem: Counting recursive elements

W

walexand

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>
 
T

Tuija Sonkkila

<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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top