I'm trying to replace "¬"-characters with "-" in strings in a XML file.
This is what I have so far (not working):
<xsl:template name="search-and-replace">
<xsl:param name="input" select="'¬'"/>
<xsl:param name="search-string" select="//text()"/>
<xsl:param name="replace-string" select="'-'"/>
<xsl:choose>
<xsl:when test="$search-string and contains($input,$search-string)">
<xsl:value-of select="substring-before($input,$search-string)"/>
<xsl:value-of select="$replace-string"/>
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input" select="substring-after($input,$search-string)"/>
<xsl:with-param name="search-string" select="$search-string"/>
<xsl:with-param name="replace-string" select="$replace-string"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Any ideas why it doesn't work?
CodePudding user response:
Even in XSLT 1, to replace one character by another, the XPath translate
function can do that job:
<xsl:template match="text()">
<xsl:value-of select="translate(., '¬', '-')"/>
</xsl:template>