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

RE: grouping consecutive elements

Subject: RE: grouping consecutive elements
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 12 Jul 2002 18:20:40 +0100
xsl group consecutive
> 
> 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@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx  


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.