Replace multiple characters per line (XSLT)

I need to be able to replace certain characters so that I can use them as CSS classes.

I have strings like class (name), class & name, amonst others, which are not valid CSS classes (as far as I can tell).

How can I use the replace function to replace multiple chracters,

eg.

translate(className, ' ','') (would replace a space) 

But is it possible to do this for a few characters?

Translation doesn't seem to work with &

Example

XML

 <title>Mary & the Wolf<title> 

XSLT

 <xsl:value-of select="translate(title, ' &','')"/></xsl:attribute> 

So, I want the result to be:

 MarytheWolf 

But at the moment I'm getting an error message with the and symbol.

+6
xslt
source share
2 answers

translate() works differently:

 translate(className, ' &#?!','') // would remove any character in the string #1 

or

 translate(className, ' &#?!','_____') // would replace any character // in the string #1 with '_' 
+7
source share

You are most there:

translate ('abcd', 'cbda', 'CBDA')

will give "ABCD".

+1
source share

All Articles