Problem: Counting recursive elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • walexand@web.de

    #1

    Problem: Counting recursive elements

    I have mistake by counting a recursive element. Can someone help me.

    XML Sample File
    ----------------------------------------------------
    <content>
    <section>
    <title>index1 </title>
    <section>
    <title>index1 1</title>
    <section>
    <title>index111 </title>
    <section>
    <title>index111 1</title>
    <section>
    <title>index111 11</title>
    <section>
    <title>index111 11</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>index1111 1</h2>
    <h2>index1111 1</h2>
    ----------------------------------------------------


    Alexander W.
  • Tuija Sonkkila

    #2
    Re: Problem: Counting recursive elements

    walexand@web.de wrote:
    [color=blue]
    > <xsl:variable name="level" select="count(./parent::section )+1" />[/color]

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

    Tuija

    Comment

    Working...