How to have multiple "To replace" special characters in xsl translate

79 Views Asked by At

How can I replace all the dash and dot on my string with a slash? I've tried using the below code.

<xsl:value-of select="translate('string_name', '-.', '/')"/>

I've also tried using the "|" but both codes don't work

<xsl:value-of select="translate('string_name', '-|.|', '/')"/>

Does anyone know a way to do this? Thank you.

I'm expecting to remove all the dots and dashes on my string and be replace by slash.

2

There are 2 best solutions below

0
y.arazim On BEST ANSWER

I think you want:

<xsl:value-of select="translate('string_name', '-.', '//')"/>

(that is, one replacement character for each character in the string of characters to be replaced).

And you probably do not want to quote the reference to the input string.

0
Martin Honnen On

Well, if you are really using a product supporting XSLT 2 then you have access to the XPath 2 function replace which would work as replace($string, '[-.]', '/').