<xsl:variable name='string'>Blah blah (Hello World) hihi</xsl:variable> <xsl:message> <xsl:value-of select="replace($string, '(\(|\))','\\$1')" /> </xsl:message>
This will work for any bracket. Your code is also incomplete. What it is? Does it contain the expected value? You are missing xsl: value-of at the end.
EDIT: after @Dimitre's comment:
<xsl:variable name="rb">(</xsl:variable> <xsl:variable name='string'>Blah blah (Hello World) hihi</xsl:variable> <xsl:message> <xsl:value-of select="replace($string, concat('\', $rb), concat('\\', $rb))" /> </xsl:message>
You will need the above results, although I see no reason to prefer this over my original solution.
source share