替换字符串中的多个字符(XSLT)

时间:2009-10-12 14:16:47

标签: xslt

我需要能够替换某些字符,以便我可以将它们用作CSS类。

我有字符串,类(名称),类和名称,amonst其他不是有效的CSS类(据我所知)。

如何使用replace函数替换多个chracters,

E.g。

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

但是有可能为多个角色做这个吗?

翻译似乎不适用于&

实施例

XML

<title>Mary & the Wolf<title>

XSLT

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

所以我希望输出为:

MarytheWolf

但此刻我和&amp;字符。

2 个答案:

答案 0 :(得分:7)

translate()以字符方式工作:

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

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

答案 1 :(得分:1)

你大部分时间都在那里:

翻译('abcd','cbda','CBDA')

会给'ABCD'。

相关问题