tags:

views:

282

answers:

2

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,

E.g.

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

But is it possible to doo this for multiple characters?

Translate doesnt seem to work with &

Example

XML

<title>Mary & the Wolf<title>

XSLT

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

So I want the output to be:

MarytheWolf

But at the moment I get an error with the & character.

A: 

translate() works character-wise:

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

or

translate(className, ' &#?!','_____')  // would replace any character 
                                       // in the string #1 with '_'
Tomalak
Thanks, seems like a good idea to replace with a char rather than nothing at all.
danit
danit
Tomalak
danit
Unless you post the complete line of code you try it with, I won't be able to tell what's wrong. ;-)
Tomalak
Edited my post added sample XML and XSLT
danit
Tomalak
+1  A: 

You're most of the way there:

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

would give 'ABCD'.

Colin Young