|
next
|
Subject: infinite loop error when trying to do multiple search/replace Author: Minollo I. Date: 20 Jan 2009 08:01 PM Originally Posted: 20 Jan 2009 08:00 PM
|
I didn't try it, but I think the problem is that you are not recursively passing find2/replace2 when you hit find/replace (and you are not passing find/replace when you hit find2/replace2); which means that if there is a match you will call contains specifying an empty string as first argument eventually. Changing it into the following should work:
<xsl:when test="contains($string,$find)">
<xsl:value-of select="concat(substring-before($string,$find),$replace)"/>
<xsl:call-template name="replace_string">
<xsl:with-param name="string" select="substring-after($string,$find)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($string,$find2)">
<xsl:value-of select="concat(substring-before($string,$find2),$replace2)"/>
<xsl:call-template name="replace_string">
<xsl:with-param name="string" select="substring-after($string,$find2)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
</xsl:call-template>
</xsl:when>
BTW, setting a breakpoint in the template and checking the variable values should help detecting those kind of problems.
|
next
|
Subject: infinite loop error when trying to do multiple search/replace Author: Riya Pillai Date: 22 Jan 2009 10:56 AM
|
Hey Minollo,
When I tried to reproduce the code for three find/replace then again I am running into the infinite loop error. Below see my code below, did I do something wrong?
<xsl:template name="replace_string">
<xsl:param name="string"/>
<xsl:param name="find"/>
<xsl:param name="replace"/>
<xsl:param name="find2"/>
<xsl:param name="replace2"/>
<xsl:param name="find3"/>
<xsl:param name="replace3"/>
<xsl:choose>
<xsl:when test="contains($string,$find)">
<xsl:call-template name="replace_string">
<xsl:with-param name="string" select="substring-before($string,$find)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
<xsl:with-param name="find3" select="$find3"/>
<xsl:with-param name="replace3" select="$replace3"/>
</xsl:call-template>
<xsl:value-of select="$replace"/>
<xsl:call-template name="replace_string">
<xsl:with-param name="string" select="substring-after($string,$find)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
<xsl:with-param name="find3" select="$find3"/>
<xsl:with-param name="replace3" select="$replace3"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($string,$find2)">
<xsl:call-template name="replace_string">
<xsl:with-param name="string" select="substring-before($string,$find2)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
<xsl:with-param name="find3" select="$find3"/>
<xsl:with-param name="replace3" select="$replace3"/>
</xsl:call-template>
<xsl:value-of select="$replace2"/>
<xsl:call-template name="replace_string">
<xsl:with-param name="string" select="substring-after($string,$find2)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
<xsl:with-param name="find3" select="$find3"/>
<xsl:with-param name="replace3" select="$replace3"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($string,$find3)">
<xsl:value-of select="concat(substring-before($string,$find3),$replace3)"/>
<xsl:call-template name="replace_string">
<xsl:with-param name="string" select="substring-after($string,$find3)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
<xsl:with-param name="find3" select="$find3"/>
<xsl:with-param name="replace3" select="$replace3"/>
</xsl:call-template>
</xsl:when>
|
|
|
|