Re: [xsl] Joining sibling elements

Subject: Re: [xsl] Joining sibling elements
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Wed, 10 Aug 2005 22:06:52 +0200
Tempore 19:49:30, die 08/10/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Marcin MiEkowski <milek_pl@xxxxx>:

<b>this</b><b> </b><b>is</b><b> </b><b>bold<text</b>

which should be transformed this:

<b>this is bold text</b>

Here's a stylesheet that will handle this simple scenario:

<xsl:stylesheet xmlns:xsl=""; version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>

<xsl:template match="*[name(preceding-sibling::node()[1])=name()]"/>

<xsl:template match="*">
		<xsl:call-template name="mergeSiblings"/>

<xsl:template name="mergeSiblings">
<xsl:for-each select="following-sibling::node()[1][name()=name(current())]">
		<xsl:call-template name="mergeSiblings"/>


The more complex case can be solved with this algorithm in multiple passes.

Joris Gillis (
Vincit omnia simplicitas
Keep it simple

Current Thread