473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

replace characters in string in xsl

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,javascript ... 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 3696
jkmyoung
2,057 Expert 2GB
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
i still can'not understand ....
Jan 29 '08 #3
jkmyoung
2,057 Expert 2GB
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
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
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...
8
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...
4
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 =...
13
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...
3
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...
9
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...
9
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...
5
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...
1
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...
7
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. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.