Re: [xsl] urgent..creating loops in output xml based on input xml values..

Subject: Re: [xsl] urgent..creating loops in output xml based on input xml values..
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Mon, 12 Sep 2005 11:48:14 +0200
Tempore 11:14:52, die 09/12/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit ma he <mahendranvm@xxxxxxxxxxx>:

Here's a working XSLT 1.0 solution. Please take the time understand it when you're not in a hurry anymore.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes"/>

<xsl:template match="root">
	<xsl:copy>
		<xsl:apply-templates select="name[.='1']"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="name">
	<Loop>
		<xsl:copy-of select="."/>
		<xsl:apply-templates select="following::name[1]" mode="recursive">
			<xsl:with-param name="level" select="number(.)+1"/>
		</xsl:apply-templates>
	</Loop>
</xsl:template>

<xsl:template match="name" mode="recursive">
	<xsl:param name="level"/>
	<xsl:if test="number(.)=$level">
		<xsl:apply-templates select="."/>
	</xsl:if>
	<xsl:if test=". &gt;= $level">
		<xsl:apply-templates select="following::name[1]" mode="recursive">
			<xsl:with-param name="level" select="$level"/>
		</xsl:apply-templates>	
	</xsl:if>
</xsl:template>

</xsl:s
tylesheet>


regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Laudeo W3C et dona ferens

Current Thread