You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by MAHE Vincent FTRD/DIH/REN <vi...@rd.francetelecom.fr> on 2000/12/08 16:15:33 UTC

How to replace chars by another string

Is there a Xalan extension which enables to subsitute all occurences of a
given character by another string ?    
For instance, I want to replace all the white spaces by the "aaa" string.
 
I've tried the translate() XPath function but I can only replace one char by
another char.
 
The instructions I used are :
<xsl:variable name="my_name_var">
     <xsl:value-of select="my_name_node"/>
</xsl:variable>
<xsl:variable name="special_string">
aaa
</xsl:variable>
 
<xsl:value-of select="translate($my_name_var,' ',$special_string)"/>
 
but it doesn't work !
 
 
Vincent.
 

Re: How to replace chars by another string

Posted by Gary L Peskin <ga...@firstech.com>.
MAHE Vincent FTRD/DIH/REN wrote:
> 
> Is there a Xalan extension which enables to subsitute all occurences of a
> given character by another string ?
> For instance, I want to replace all the white spaces by the "aaa" string.
> 
> I've tried the translate() XPath function but I can only replace one char by
> another char.

Yes, translate will only substitute a single character.  There is no
extension function that I know of written yet.  Please feel free to
write one and contribute the code.

Also, a "grep" extension function is planned for XalanJ2 that may
support such substitution.

For doing this in pure XSLT, see
http://www.dpawson.co.uk/xsl/stringreplace.html#N34004

Gary