Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Text replacement

Reply
Thread Tools

Text replacement

 
 
Markus
Guest
Posts: n/a
 
      12-16-2005
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

 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      12-16-2005
Read about the translate() function.

Cheers,
Dimitre Novatchev

"Markus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
 
 
 
Magnus Henriksson
Guest
Posts: n/a
 
      12-16-2005
"Markus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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


 
Reply With Quote
 
Magnus Henriksson
Guest
Posts: n/a
 
      12-16-2005
"Magnus Henriksson" <(E-Mail Removed)> wrote in message
news:dnu21q$j9p$(E-Mail Removed)...

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


// Magnus


 
Reply With Quote
 
Markus
Guest
Posts: n/a
 
      12-16-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Writing Replacement Text to Files Thomas Pierce Ruby 6 02-18-2008 03:36 PM
Regex Replacement: Replacing text with an empty string Hal Vaughan Java 9 12-26-2007 04:15 AM
Selecting Text in Input in FF and/or Safari (replacement for TypeAheadSelect) Phrogz Javascript 1 10-31-2006 06:46 PM
xml parsing and text replacement Robert Mark Bram ASP General 3 03-01-2004 11:17 AM
re.sub replacement text \-escapes woe Alexander Schmolck Python 4 02-14-2004 02:30 AM



Advertisments