[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl-grouping two different elements together
gregor FELLENZ wrote:
given the following structure: The following stylesheet achieves the output: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes"/> <xsl:key name="k1" match="kapitel/leerzeile" use="generate-id(preceding-sibling::*[starts-with(local-name(), 'einschub')][1])"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@*, node()"/> </xsl:copy> </xsl:template> <xsl:template match="kapitel"> <xsl:copy> <xsl:for-each-group select="* except leerzeile" group-adjacent="node-name(.)"> <xsl:choose> <xsl:when test="starts-with(local-name-from-QName(current-grouping-key()), 'einschub')"> <einschub typ="{replace(local-name-from-QName(current-grouping-key()), '[^0-9]+', '')}"> <xsl:apply-templates select="current-group()"/> </einschub> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> <xsl:template match="einschub1|einschub2"> <abs> <xsl:apply-templates/> </abs> <xsl:apply-templates select="key('k1', generate-id())"/> </xsl:template> </xsl:stylesheet> but I am not sure it will work as you want with other possible input documents you might have. Where all can "leerzeile" elements occur? What determines where they have to end up in the result? -- Martin Honnen http://msmvps.com/blogs/martin_honnen/
|
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
|