Hello,
I am working with XSLT 1.0 (so I can't use the replace() function), and I need to make a replace in a string, before use that string for sorting. Briefly, my XML doc looks like this:
<root>
<item>
<name>ABC</name>
<rating>good</rating>
</item>
<item>
<name>BCD</name>
<rating>3</rating>
</item>
</root>
Then I need to replace 'good' with '4', in order to print the whole items list ordered by rating using the sort() function. Since I'm using XSLT 1.0, I use this template for replacements:
<xsl:template name="string-replace">
<xsl:param name="subject" select="''" />
<xsl:param name="search" select="''" />
<xsl:param name="replacement" select="''" />
<xsl:param name="global" select="false()" />
<xsl:choose>
<xsl:when test="contains($subject, $search)">
<xsl:value-of select="substring-before($subject, $search)" />
<xsl:value-of select="$replacement" />
<xsl:variable name="rest" select="substring-after($subject, $search)" />
<xsl:choose>
<xsl:when test="$global">
<xsl:call-template name="string-replace">
<xsl:with-param name="subject" select="$rest" />
<xsl:with-param name="search" select="$search" />
<xsl:with-param name="replacement" select="$replacement" />
<xsl:with-param name="global" select="$global" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$rest" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$subject" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This templates works fine, but the problem is that it always print the values, (i.e. always when I call the template something is printed). Therefore, this template is not usefull in this case, because I need to modify the 'rating' value, then sort the items by rating and finally print them.
Thanks in advance!
PS: A workaround would be use two different XSLT, but for several reasons I can't do it in this case.