[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|