[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Joining sibling elements

Subject: Re: Joining sibling elements
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Wed, 10 Aug 2005 22:06:52 +0200
Re:  Joining sibling elements
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="http://www.w3.org/1999/XSL/Transform" 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:copy>
		<xsl:apply-templates/>
		<xsl:call-template name="mergeSiblings"/>
	</xsl:copy>
</xsl:template>

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

</xsl:stylesheet>

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

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Vincit omnia simplicitas
Keep it simple

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.