Subject: RE: [xsl] grouping consecutive elements From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Fri, 12 Jul 2002 18:20:40 +0100 |
> > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] grouping consecutive elements, Arregi Iparragirre. | Thread | [xsl] single HTML tag around repeat, Brad Miller |
RE: [xsl] XML to plain text : which, Michael Kay | Date | RE: [xsl] Escaping single quote, Michael Kay |
Month |