Subject: RE: [xsl] strings and recursive templates From: "Américo Albuquerque" <aalbuquerque@xxxxxxxxxxxxxxxx> Date: Fri, 19 Jul 2002 12:30:42 +0100 |
Hi Andrew <xsl:template name="t2"> <xsl:param name="string" select="''"/> <xsl:if test="contains($string,'|')"> <xsl:value-of select="substring-before($string,'|')"/> <xsl:call-template name="t2"> <xsl:with-param name="string" select="substring-after($string,'|')"/> </xsl:call-template> </xsl:if> <xsl:value-of select="$string"/> <---- here his your problem it shows the string even when a match is found </xsl:template> change that line to: <xsl:if test="not(contains($string,'|'))"> <xsl:value-of select="$string"/> </xsl:if> and it should work -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Andrew Welch Sent: Friday, July 19, 2002 12:09 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] strings and recursive templates I would have thought the following templates should produce the same result, one uses choose/when, one uses if, however the value-of at the end of template t2 seems to keep track of the whole string... if I step through the code the debugger stays on that line the number of times the template has been recursively called - which is a bit strange... Using this data: <node>1 | 2 | 3 | 4 | 5</node> I would expect this result: 1 2 3 4 5 which is what t1 gives me, whereas t2 produces: 1 2 3 4 5 4 | 5 3 | 4 | 5 2 | 3 | 4 | 51 | 2 | 3 | 4 | 5 why is this? saxon and msxml4 both produce the same so Im guessing its a gap in my understanding rather than a processor issue... <xsl:template name="t1"> <xsl:param name="string" select="''"/> <xsl:choose> <xsl:when test="contains($string,'|')"> <xsl:value-of select="substring-before($string,'|')"/> <xsl:call-template name="t1"> <xsl:with-param name="string" select="substring-after($string,'|')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="t2"> <xsl:param name="string" select="''"/> <xsl:if test="contains($string,'|')"> <xsl:value-of select="substring-before($string,'|')"/> <xsl:call-template name="t2"> <xsl:with-param name="string" select="substring-after($string,'|')"/> </xsl:call-template> </xsl:if> <xsl:value-of select="$string"/> </xsl:template> cheers andrew --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.373 / Virus Database: 208 - Release Date: 01/07/2002 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] strings and recursive templat, Andrew Welch | Thread | Re: [xsl] strings and recursive tem, David Carlisle |
RE: [xsl] The longest node in a nod, DPawson | Date | Re: [xsl] strings and recursive tem, David Carlisle |
Month |