Re: [xsl] xsl:for-each-group and identity transform

Subject: Re: [xsl] xsl:for-each-group and identity transform
From: Jesper Tverskov <jesper.tverskov@xxxxxxxxx>
Date: Fri, 23 Jan 2009 18:08:10 +0100
Sorry, forgot the new stylesheet. The impossible turned out to be easy.

We have now identity transformation and xsl:for-each-group working side by side:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0" xmlns="http://www.w3.org/1999/xhtml";
xpath-default-namespace="http://www.w3.org/1999/xhtml";>
<xsl:output method="xml" indent="yes"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>		
</xsl:template>	

<xsl:template match="body">
<xsl:copy>
<xsl:for-each-group
select="element()|comment()|processing-instruction()"
group-starting-with="h1">
<xsl:apply-templates select="." mode="group"/>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>

<xsl:template match="h1" mode="group">
<h>
<xsl:copy-of select="node()"/>
</h>
<xsl:for-each-group select="current-group() except ." group-starting-with="h2">
<xsl:apply-templates select="." mode="group"/>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="h2|h3|h4|h5|h6" mode="group">
<xsl:variable name="this" select="name()"/>
<xsl:variable name="next" select="translate($this, '23456', '34567')"/>
<section>
<h>
<xsl:copy-of select="node()"/>
</h>
<xsl:for-each-group select="current-group() except ."
group-starting-with="*[name() = $next]">
<xsl:apply-templates select="." mode="group"/>
</xsl:for-each-group>
</section>
</xsl:template>

<xsl:template match="element()|comment()|processing-instruction()" mode="group">
<xsl:apply-templates select="current-group()"/>
</xsl:template>
	
<!-- more templates here to delete what is copied out of DTD -->	
<xsl:template match="@shape"/>	
</xsl:stylesheet>

Cheers,
Jesper Tverskov

Current Thread