[xsl] Grouping Adjacent Elements in XSLT 1.0 and Duplicates

Subject: [xsl] Grouping Adjacent Elements in XSLT 1.0 and Duplicates
From: "Joe Heidenreich" <HeidenreichJ@xxxxxxxx>
Date: Wed, 20 Oct 2004 15:32:57 -0400
For my translation, my input looks like this:

<para>text1</para>
<para>text2</para>
<ol_li>first ordered list element 1</ol_li>
<ol_li>first ordered list element 2</ol_li>
<ol_li>first ordered list element 3</ol_li>
<para>text3</para>
<para>text4</para>
<para>text5</para>
<ol_li>second ordered list element 1</ol_li>
<ol_li>second ordered list element 2</ol_li>

The output needs to look like this:

<p>text1</p>
<p>text2</p>
<ol>
     <li>first ordered list element 1</li>
     <li>first ordered list element 2</li>
     <li>first ordered list element 3</li>
</ol>
<p>text3</p>
<p>text4</p>
<p>text5</p>
<ol>
     <li>second ordered list element 1</li>
     <li>second ordered list element 2</li>
</ol>

The number of lists and items and paragraphs will vary.

Currently my stylesheet looks like this:

...
<xsl:template match="para">
     <p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="ol_li">
     <p>
          <ol>
               <xsl:apply-templates select="." mode="list-item" />
          </ol>
     </p>
     <xsl:apply-templates
select="following-sibling::node()[not(self::ol_li)][1]" />
</xsl:template>

<xsl:template match="ol_li" mode="list-item">
     <li>
          <xsl:apply-templates/>
     </li>
     <xsl:apply-templates mode="list-item"
select="following-sibling::node()[1][self::ol_li]" />
</xsl:template>
...

But the output is yielding decrementing duplicates like this:

<p>
<ol>
<li>first ordered list element 1</li>
<li>first ordered list element 2</li>
<li>first ordered list element 3</li>
</ol>
</p>

<p>
<ol>
<li>first ordered list element 2</li>
<li>first ordered list element 3</li>
</ol>
</p>

<p>
<ol>
<li>first ordered list element 3</li>
</ol>
</p>

It seems to be a recursion problem but i would appreciate any help I could
get. Thanks.
-Joe

Current Thread