469,297 Members | 2,134 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,297 developers. It's quick & easy.

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 3247
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

Post your reply

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

Similar topics

14 posts views Thread by Nicolas Bouillon | last post: by
3 posts views Thread by o_swas | last post: by
9 posts views Thread by David P. Donahue | last post: by
5 posts views Thread by djc | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.