[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Re: xsl:for-each-group and identity transform
From: Jesper Tverskov <jesper.tverskov@xxxxxxxxx>
Date: Fri, 23 Jan 2009 18:08:10 +0100
Re:  xsl:for-each-group and identity transform
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.