RE: [xsl] Infinite Recursion Looking for Whitespace.

Subject: RE: [xsl] Infinite Recursion Looking for Whitespace.
From: "Andy J. Cupp" <acupp@xxxxxxxxxxxxxxx>
Date: Mon, 27 Jan 2003 13:36:44 -0600
Heath,
	I think this will work with a couple changes.  First, your <xsl:if> element has a substring function that uses '-1' as an argument.  Shouldn't it just be positive 1?  Also, whenever you refer to a number in an expression, I don't think there's any reason to put quotes around the number.  So "substring($leftStringValue,number($leftStringLength),'1')" should just be "substring($leftStringValue,number($leftStringLength),1)".  I ran your code with these changes and it worked for me.  
Hope this helps,
Andy

-----Original Message-----
From: HEATH ALLISON [mailto:HEATH.ALLISON@xxxxxxxxxxxxxxx]
Sent: Monday, January 27, 2003 12:21 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Infinite Recursion Looking for Whitespace.


Andy,

I've amended the code below to show a "failsafe" I added to the if statement:

<xsl:template name="looper">
	<xsl:param name="leftStringLength"/>
	<xsl:param name="leftStringValue"/>
		
		<xsl:if test="substring($leftStringValue,number($leftStringLength),'-1') != 't' and $leftStringLength >0 ">

		String Length: <xsl:value-of select="$leftStringLength" /> <BR/>
		String Value: <xsl:value-of select="$leftStringValue" /> <BR/>
		String End: <xsl:value-of select="substring($leftStringValue,number($leftStringLength),'1')" /><BR/>
		
		<!-- recursive call -->
			<xsl:call-template name="looper">
				<xsl:with-param name="leftStringLength" select="$leftStringLength - 1"/>
				<xsl:with-param name="leftStringValue" select="substring($leftStringValue,'1',number($leftStringLength)-'1')" />
			</xsl:call-template> 
		</xsl:if>
	
</xsl:template>

I've put some debug code in there to write out the values of both the stringlength and the stringvalue. It's rifling through one character at a time, but it's ignoring the condition to test the value of the character... it stops on the "and" condition of >0 but not on the != condition of whatever character I supply...

heath deforrest allison
"Arrowed!"




-----Original Message-----
From: Andy J. Cupp [mailto:acupp@xxxxxxxxxxxxxxx]
Sent: Monday, January 27, 2003 11:51 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Infinite Recursion Looking for Whitespace.


Hi Allison.  From your remarks, it seems you may have worked on this already, but I think you need an additional test to end the recursion.  Currently, if the template never encounters a blank space, it will just keep looping, sending nothing as the $leftStringValue parameter and -1,-2,-3,... as the $leftStringLeft parameter.  Maybe if you just have a test in the form of <xsl:if test="$leftStringValue">, that would end your recursion when the string has been examined.

-----Original Message-----
From: HEATH ALLISON [mailto:HEATH.ALLISON@xxxxxxxxxxxxxxx]
Sent: Monday, January 27, 2003 10:57 AM
To: XSL List
Subject: [xsl] Infinite Recursion Looking for Whitespace.


Hello again, I'm still trying to fix my line-break problem. I'm trying to get my recursion loop to rifle through the value of $leftStringValue from the end to the start, but stop when it encounters the first blank space. The xsl:if test works if I set it to the value of $stringLength with a test of "> 0". But the second I change it to look for a space at the last position in a substring of $stringValue it goes infinite and overflows the stack. Any suggestions?

<xsl:template name="loop">
	<xsl:param name="leftStringLength"/>
	<xsl:param name="leftStringValue"/>
		
		<xsl:if test="(normalize-space(substring($leftStringValue,number($leftStringLength),'1'))) != ' ' ">

		String Length: <xsl:value-of select="$leftStringLength" /> <BR/>
		String Value: <xsl:value-of select="$leftStringValue" /> <BR/>
		String End: <xsl:value-of select="substring($leftStringValue,number($leftStringLength),'1')" /><BR/>
		
		<!-- recursive call -->
			<xsl:call-template name="loop">
				<xsl:with-param name="leftStringLength" select="$leftStringLength - 1"/>
				<xsl:with-param name="leftStringValue" select="substring($leftStringValue,'1',number($leftStringLength)-'1')" />
			</xsl:call-template> 
		</xsl:if>
	
</xsl:template>


heath deforrest allison
"Arrowed!"




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 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