Re: [xsl] Convert copyright symbol to string "Copyright"

Subject: Re: [xsl] Convert copyright symbol to string "Copyright"
From: Geert Josten <Geert.Josten@xxxxxxxxxxx>
Date: Sat, 27 Nov 2004 09:51:33 +0100
Same here, several string replace solutions can be found on:

http://www.dpawson.co.uk/xsl/sect2/replace.html

Grtz,
Geert

Whitney, Dan (CanWest Interactive) wrote:

Using xsl version 1.0 I am trying to convert a copyright symbol to the text
string "Copyright". I tried doing a <xsl:value-of select="translate(.,
copyrightsymbol, 'C')"/> which works great, but can't make the translate
more than 1 char.

The translate function is designed to translate character to character or character entity to character entity. It works well when you want to convert text from upper case to lowercase or for single charcter conversion but it won't work as a standard search and replace utility for strings of variable length.


Have looked all over the place for a solution but haven't
had much luck. Do I have to search each character in text see if it matches
the symbol and then replace it or is there a simpler method like above?


The way to accomplish this with XSLT 1.0 is to use recursive named templates. The idea is to call a named template, passing it a string value to translate. Within that template you do a simple test to see if a certain string exists using the contains function. If it does you then use a combination of string functions (substring-before, substring-after, et Al.) to take what comes before and after the matching string and stick it in front of and in back of the string value in which you want to replace the string with. By then calling the template again you can use the same logic from before to check if there are any more instances of the string you want to replace. By using <xsl:if .../> as a way to test for a strings existence if it doesnt exist then the "loop" will cease and the remainder of the stylesheet processing will continue.

Let me know if this makes sense and/or a code sample would help see things a little more clearly.

Best regards,

<M:D/>




-- Geert.Josten@xxxxxxxxxxx IT-consultant at Daidalos BV, Zoetermeer (NL)

http://www.daidalos.nl/
tel:+31-(0)79-3316961
fax:+31-(0)79-3316464

GPG: 1024D/12DEBB50

Current Thread