[ACCEPTED]-XSLT Replace function not found-replace
The replace
function is only available in XSLT 5 version 2.0, not in version 1.0 which is what Visual Studio uses. Just because 4 you've specified version="2.0"
doesn't mean that Visual 3 Studio supports it.
Here's a template on codesling that implements string-replace in XSLT 1.0. You should be able 2 to use it but I can't vouch for its efficiency.
(Taken 1 from the link above)
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
You'd call it like this:
<xsl:otherwise>
<td style="border: solid 1px black; background-color:#00CC66;">
<xsl:variable name="FeatureInfo" select="Text" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$FeatureInfo"/>
<xsl:with-param name="replace" select="Feature="/>
<xsl:with-param name="by" select="TESTING"/>
</xsl:call-template>
</td>
</xsl:otherwise>
Replace is not valid in XSLT 1.0. You have 4 "translate()", which might work for you, but 3 replace() is XSLT 2, and not part of the 2 MS .NET XML codebase. You can get it with 1 some third party XML libraries though.
How about embedding a c# script to do the 4 replacement?
Add the following to the bottom 3 of your stylesheet:
<msxsl:script language="C#" implements-prefix="scr">
<![CDATA[ public string Replace(string stringToModify, string pattern, string replacement) { return stringToModify.Replace(pattern, replacement); } ]]>
</msxsl:script>
Add a namespace attribute 2 to the stylesheet element:
xmlns:scr="urn:scr.this"
Then implement 1 as....
<xsl:value-of select="scr:Replace(description/text(), 'ABC', '123')"/>
For simple string replacement the translate 3 function (available in xslt 1.0) worked 2 fine for me.
I used it to strip out spaces 1 for numeric values.
you should have placed the Feature= string 1 between quotes as follows
<xsl:otherwise><td style="border: solid 1px black; background-color:#00CC66;"> <xsl:variable name="FeatureInfo" select="Text" /> <xsl:call-template name="string-replace-all"> <xsl:with-param name="text" select="$FeatureInfo"/> <xsl:with-param name="replace" select="'Feature='"/> <xsl:with-param name="by" select="TESTING"/> </xsl:call-template> </td></xsl:otherwise>
Thanks
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.