Text replacement

M

Markus

Hello,

I have a question concerning XSL and text replacement. I have the
following simple XML structure:
<data>
<element>ř{Dž</element>
</data>

Now I want to transform this to:
<data>
<element>+++</element>
</data>

So what I want to do is to replace parts of the form &#<number>; with a
special character (e.g. +). Of course I want to do this in attribute
values too and it might be possible that a string is mixed:
řab{cdefDž will be transformed to +ab+cdef+. Is it
possible to do this in XSL with
a) no self written extension (only standards)
b) the usage of XSL 1.0 (no absolute necessary)?

Regards
Markus
 
M

Magnus Henriksson

Markus said:
Hello,

I have a question concerning XSL and text replacement. I have the
following simple XML structure:
<data>
<element>ř{Dž</element>
</data>

Now I want to transform this to:
<data>
<element>+++</element>
</data>

So what I want to do is to replace parts of the form &#<number>; with a
special character (e.g. +). Of course I want to do this in attribute
values too and it might be possible that a string is mixed:
řab{cdefDž will be transformed to +ab+cdef+. Is it
possible to do this in XSL with
a) no self written extension (only standards)
b) the usage of XSL 1.0 (no absolute necessary)?


Do you want to replace all *character references* with special characters,
or do you just want to replace some *characters*?

By the time the XML source gets to the XSLT processor, all traces of
character references are gone; all that is left are UTF-8 characters. This
means that it is not possible to determine whether a character was in the
form of the character reference in the source, or just a character.

Having said that, if you have a subset of characters that you want to
replace with some other character, you can use the translate() function
(http://www.w3.org/TR/xpath#function-translate). For example:
translate('string to replace characters in','abcdef','+') returns the string
"string to r+pl+++ +h+r++t+rs in".


// Magnus
 
M

Magnus Henriksson

That should of course be: translate('string to replace characters
in','abcdef','++++++').


// Magnus
 
M

Markus

Thanks for the information. I just didn't know that all character
references have been resolved, when the XML source gets to the XSLT
processor.

Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top