This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: grouping consecutive elements
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 12 Jul 2002 18:20:40 +0100
- Subject: RE: [xsl] grouping consecutive elements
- Reply-to: xsl-list at lists dot mulberrytech dot com
>
> trying to transform an XML document obtained by using MajiX
> we donīt know how to group consecutive XML elements into a
> single one. For example we want to group consecutive <b>
> siblings into a single <b> or consecutive <i> into a single
> <i>, keeping always their internal structure.
>
It's not actually an easy problem. The following kind of technique is
sometimes useful:
<xsl:template match="b">
<b>
<xsl:copy-of select="."/>
<xsl:apply-templates
select="following-sibling::*[1][self::b]"
mode="more"/>
</b>
<xsl:apply-templates
select="following-sibling::[not(self::b)][1]"/>
</xsl:template>
<xsl:template match="b" mode="more">
<xsl:copy-of select="."/>
<xsl:apply-templates
select="following-sibling::*[1][self::b]"
mode="more"/>
</xsl:template>
and similarly for the other elements that occur. It's basically applying
templates "horizontally" rather than "vertically", a special case of
recursive processing rather than iterative processing.
Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list