Problem: Counting recursive elements

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

  1. Guest

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


    Alexander W.
     
    , Aug 11, 2004
    #1
    1. Advertising

  2. wrote:

    > <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
     
    Tuija Sonkkila, Aug 11, 2004
    #2
    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. Michael H Lees

    finding/counting elements in a STL::map

    Michael H Lees, Jun 26, 2003, in forum: C++
    Replies:
    3
    Views:
    5,552
    Samuele Armondi
    Jun 27, 2003
  2. Alf P. Steinbach
    Replies:
    2
    Views:
    551
    Chris Theis
    Feb 5, 2004
  3. n00m
    Replies:
    12
    Views:
    1,143
  4. vamsi
    Replies:
    21
    Views:
    2,153
    Keith Thompson
    Mar 9, 2009
  5. edwardfredriks

    counting up instead of counting down

    edwardfredriks, Sep 6, 2005, in forum: Javascript
    Replies:
    6
    Views:
    241
    Dr John Stockton
    Sep 7, 2005
Loading...

Share This Page