Don Stinchfield wrote:
I'm in the process of breaking up an XHTML file into multiple XML files.
...
<heading level="h1"><a name="content" id="content"></a>Overview</heading>
<p>On February 20, 1865</p>
...
<heading level="h3"><a name="mission" id="mission"></a>Mission</heading>
I'm cleaning up a bit and would like to add structure as follows...
<section>
<heading level="h1">Overview</heading>
<p>On February 20, 1865</p>
...
</section>
<section>
<heading level="h3"></a>Mission</heading>
A kind of grouping problem.
- <xsl:template match="x:heading">
- <section>
- <title>
<xsl:value-of select="." />
</title>
<xsl:apply-templates select="following-sibling::*" />
...
The above puts me in an infinite loop.
Not necessarily infinite but certainly O(n^2) behaviour. Think about
it.
Instead of *all* following siblings of a heading, you want to select
only siblings whose first preceding header sibling is the matched
header.
Or in XPath:
select="following-sibling::*[
generate-id(preceding-sibling::x:header[1])=
generate-id(current())]"
There are several other possiblities to express this, some of
which may have a better performance.
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list