[Home] [By Thread] [By Date] [Recent Entries]
Batis DAVE wrote:
Hi Dave,I want to return a value from a template(getIdList). The returned value is saved in a variable ($idList) and is a string wich is the concatenation of my nodes id : id1,id2,id3,... I use this code wich is not working... i got nothing when i display the variable value...!! for the first, you cannot pass parameters to a template with select and match. The other problem is the scope of the variable 'var'. It only lives within the scope of the for-each. So if you try to get a value from it outside the foreach it is empty (it is not defined) See the stylesheet below for a newbie-solution. It uses recursion. regards, Ruud <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes" method="html" omit-xml-declaration="no" encoding="ISO-8859-1" /> <xsl:param name="delimiter" select="','"/> <xsl:template match="/root">
<xsl:variable name="idList">
<xsl:call-template name="getIdList">
<xsl:with-param name='list' select="/root/vid"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$idList"/>
</xsl:template><xsl:template name="getIdList"> <xsl:param name='list'/> <xsl:if test="count($list) > 0"> <xsl:value-of select='$list[1]'/> <xsl:text>,</xsl:text> <xsl:call-template name="getIdList" > <xsl:with-param name='list' select="$list[1]/following-sibling::*"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet>
|

Cart



