473,881 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

replace characters in string in xsl

52 New Member
hello i am very new in xsl ,xml so ....forgive me if i make spuped questions..


well i have the string e.g. <script> blabla bla </script> i want to replace in xsl the special characters like < ,/ with encoded like '#231'
my real problem is wich replace function to use to do it in the whole string?? i know how to do it in java,vb6,javasc ript ... but i can't find out how to do it in xsl. code example would be very helpfull!!!

thanks in advance
Jan 28 '08 #1
4 3750
jkmyoung
2,057 Recognized Expert Top Contributor
Fairly common request:
Expand|Select|Wrap|Line Numbers
  1.  <!-- reusable replace-string function -->
  2.  <xsl:template name="replace-string">
  3.     <xsl:param name="text"/>
  4.     <xsl:param name="from"/>
  5.     <xsl:param name="to"/>
  6.  
  7.     <xsl:choose>
  8.       <xsl:when test="contains($text, $from)">
  9.  
  10.     <xsl:variable name="before" select="substring-before($text, $from)"/>
  11.     <xsl:variable name="after" select="substring-after($text, $from)"/>
  12.     <xsl:variable name="prefix" select="concat($before, $to)"/>
  13.  
  14.     <xsl:value-of select="$before"/>
  15.     <xsl:value-of select="$to"/>
  16.         <xsl:call-template name="replace-string">
  17.       <xsl:with-param name="text" select="$after"/>
  18.       <xsl:with-param name="from" select="$from"/>
  19.       <xsl:with-param name="to" select="$to"/>
  20.     </xsl:call-template>
  21.       </xsl:when> 
  22.       <xsl:otherwise>
  23.         <xsl:value-of select="$text"/>  
  24.       </xsl:otherwise>
  25.     </xsl:choose>            
  26.  </xsl:template>
  27.  
http://aspn.activestate.com/ASPN/Coo...T/Recipe/65426
Jan 28 '08 #2
chriskaza81
52 New Member
i still can'not understand ....
Jan 29 '08 #3
jkmyoung
2,057 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. <xsl:call-template name="replace-string">
  2.     <xsl:with-param name="text" select="script"/>
  3.     <xsl:with-param name="from" select="'&lt;'"/>
  4.     <xsl:with-param name="to" select="'#231'"/>
  5. </xsl:call-template>
  6.  
Note, < has been unescaped from &lt; by this forum.
Jan 29 '08 #4
chriskaza81
52 New Member
thanks a lot i tested in Oxigen it is work as expected, but not i my project probably because it is oracle database and for some reason it doesn't work
Jan 30 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
16151
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike non ascii chars... Can you help me please ? Thanks.
8
4077
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had problems getting my algorithm to work and in order to help me find the solution I decided to print each line to screen as I read them. Then, to my surprise, I noticed that there was a space between every character as I outputted the lines to the...
4
1905
by: Prasad S | last post by:
Hello I wish to replace all the characters in a string except those which are inside '<' & '>' characters. And there could be multiple occurences of < & > within the string. e.g. string = "this is an example of <how> many words could be hidden <under> these characters" now, from this string all the characters should be searched & replaced
13
11035
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code below would work... string gsub(const string & sData, const string & sFrom,
3
30418
by: o_swas | last post by:
Hello, I have a JavaScript string. I want to replace all consecutive occurrences of whitespace characters like spaces, tabs, newlines, and form feeds with another string. For example, say I have a string consisting of: -- 3 spaces -- The characters "hello"
9
2098
by: David P. Donahue | last post by:
I'm using RegExp.Replace(string, string, string) to remove some pieces of large strings. But I seem to be having trouble getting it to match "all characters up to and including xxxxx" (which I thought would be ".*xxxxx" but it's not working). I can get it to match more precise segments no problem, but not "all characters up to and including xxxxx" or "xxxxx and all characters after it." Any ideas? Regards, David P. Donahue
9
9174
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a StringBuilder. At present I am porting a VB6 webclass app to VB.NET and therefore I am trying to make it as efficent as possible via the new functionality of VB.NET.
5
2447
by: djc | last post by:
I need to prepare a large text database field to display in an asp.net repeater control. Currently I am replacing all chr(13)'s with a "<br/>" and it works fine. However, now I also want to be able to replace TAB's with "&nbsp;"'s to preserve the user's indentation. My questions are: 1) even though I'll probably look it up before I get a reply.... whats the vb code for TAB character? 2) more importantly; do I have to run this large field...
1
2917
by: coolami4u | last post by:
I need a program that simulates the search-and-replace operation in a text editor. The program is to have only three function calls in main. The first function prompts the user to type a string of fewer than 80 characters. It then prompts the user to type the search-substring of 10 or fewer characters. Finally, it prompts the user to type the replace-substring of 10 or fewer characters. The second function call is the search-and-replace...
7
3799
by: Grok | last post by:
I need an elegant way to remove any characters in a string if they are not in an allowed char list. The part cleaning files of the non-allowed characters will run as a service, so no forms here. The list also needs to be editable by the end-user so I'll be providing a form on which they can edit the allowed character list. The end-user is non-technical so asking them to type a regular expression is out.
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11104
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10724
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10825
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7953
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.