This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: grouping consecutive elements


> 
> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]