Re: [xsl] recursive loop in XSL stylesheet is failing

Subject: Re: [xsl] recursive loop in XSL stylesheet is failing
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Thu, 25 Mar 2010 20:05:42 +0100
George wrote:
Thanks a lot guys in order to shed light on my view about variables!!

Great, thank you very much David for the modified stylesheet.

Unfortunately it does not give the result I expected. It stops after the output of Date. It seems that it does not like the key() function.

Are you sure that it is called correctly this way:
 > <xsl:apply-templates select="key('c',CategoryID,$c)"/>

Yes, that is possible, but only with XSLT 2.0 (that David used).


If you use XSLT 1.0 then you need to change the code slightly:


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:key name="c" match="Category" use="@ID"/>
<xsl:variable name="c" select="document('Categories.xml')"/>
<xsl:template match="Entry">
<xsl:text>&#10;</xsl:text>
<xsl:value-of select="Date"/>
<xsl:apply-templates select="key('c',CategoryID,$c)"/>

Change the above line to <xsl:variable name="cat" select="CategoryID"/> <xsl:for-each select="$c"> <xsl:apply-templates select="key('c', $cat)"/> </xsl:for-each>

<xsl:text>;</xsl:text>
<xsl:value-of select="Recipient"/>
<xsl:text>;</xsl:text>
<xsl:value-of select="Value"/>
</xsl:template>

<xsl:template match="Category">
 <xsl:apply-templates select="key('c',@ParentID,$c)"/>

and the above line to <xsl:variable name="pid" select="@ParentID"/> <xsl:for-each select="$c"> <xsl:apply-templates select="key('c', $pid)"/> </xsl:for-each>



--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread