[Home] [By Thread] [By Date] [Recent Entries]
Kolacm Toma9 wrote:
I have following input XML: I think this stylesheet does what you want: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:key name="a-group" match="a" use="generate-id(preceding-sibling::*[not(self::a)][1])"/> <xsl:template match="root">
<xsl:copy>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template><xsl:template match="a[preceding-sibling::*[1][not(self::a)] or not(preceding-sibling::*)]"> <a-block> <xsl:apply-templates select="key('a-group', generate-id(preceding-sibling::*[not(self::a)][1]))" mode="copy"/> </a-block> </xsl:template> <xsl:template match="a[preceding-sibling::*[1][self::a]]"/> <xsl:template match="a" mode="copy">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template><xsl:template match="* | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template></xsl:stylesheet> -- Martin Honnen
|

Cart



