RE: [xsl] XSLT 1.0: Grouping Adjacent Elements in Embedded Lists

Subject: RE: [xsl] XSLT 1.0: Grouping Adjacent Elements in Embedded Lists
From: "Joe Heidenreich" <HeidenreichJ@xxxxxxxx>
Date: Fri, 5 Nov 2004 10:33:45 -0500
Hi Wendell,

When I do this:

> <xsl:if test="not(preceding-sibling::OL_LI)">
>    <p>
>      <ol>
>        <xsl:apply-templates select="." mode="li"/>
>      </ol>
>    </p>
> </xsl:if>

Then, my <OL_LI> items aren't processed at all in the embedded list. Though I
have an <OL_LI> list without embedded items that shows up fine.

And when I do this:

> <xsl:if test="not(preceding-sibling::*[1][self::OL_LI|self::EM_OL_LI])">
>    <p>
>      <ol>
>        <xsl:apply-templates select="." mode="li"/>
>      </ol>
>    </p>
> </xsl:if>

<p>
   <ol>
      <li>Top: Item 1</li>
      <p>
         <ol>
            <li>Sub A: Item 1</li>
         </ol>
      </p>
   </ol>
</p>

Which truncates the list when encountering the first <OL_LI> after a
<EM_OL_LI> tag. I am indeed using a very flat file which I am trying to add
hierarchy to. PARA tags are mixed in with OL_LI tags and EM_OL_LI tags. Sample
input is like:

<HEAD>
<PARA>
<PARA>
<OL_LI>
<OL_LI>
<EM_OL_LI>
<OL_LI>
<HEAD>
<PARA>

And I'm adding hierarchy through this:

<xsl:key name='stuffchildren' match="PARA | OL_LI"
  use="generate-id((..|preceding-sibling::HEAD)[last()])"/>

<xsl:template name="process-body">
  <xsl:apply-templates select="key('stuffchildren', generate-id())"/>
  <xsl:apply-templates select="HEAD"/>
</xsl:template>


<xsl:template match="HEAD">
  <sec>
    <title>
      <xsl:apply-templates/>
    </title>
    <xsl:apply-templates select="key('stuffchildren', generate-id())"/>
  </sec>
</xsl:template>


Which I thought could be part of my problem. But when I change it to be

<xsl:key name='stuffchildren' match="PARA | OL_LI | EM_OL_LI"
  use="generate-id((..|preceding-sibling::HEAD)[last()])"/>

so that it accounts for <EM_OL_LI> tags as well I get:

<p>
   <ol>
      <li>Top: Item 1</li>
      <p>
         <ol>
            <li>Sub A: Item 1</li>
         </ol>
      </p>
   </ol>
</p>
<p>
   <ol>
      <li>Sub A: Item1</li>
   </ol>
</p>
...

With all of the embedded lists being repeated in separate paragraphs at the
top level.

Thanks!

-Joe

Current Thread