Subject: Re: flatened hiearchies for xslt2
From: ac <ac@xxxxxxxxxxxxx>
Date: Wed, 07 Mar 2007 12:48:44 -0500
|
Hi
Thank you David.
Great stuff with an interestingly slightly twisted and elegant solution.
I am not surprised that it is a classic.
Thanks,
Andre
This is a classic for-each-group example:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="section" name="group">
<xsl:param name="s" select="section"/>
<xsl:param name="l" select="1"/>
<xsl:for-each-group select="$s" group-starting-with="*[@level=$l]">
<section id="{@id}">
<xsl:call-template name="group">
<xsl:with-param name="s" select="current-group()[position()!=1]"/>
<xsl:with-param name="l" select="$l+1"/>
</xsl:call-template>
</section>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
saxon8 fl.xml fl.xsl \!indent=yes
<?xml version="1.0" encoding="UTF-8"?>
<section id="1">
<section id="1-1"/>
<section id="1-2">
<section id="1-2-1"/>
<section id="1-2-2"/>
</section>
</section>
<section id="2"/>
David
|