472,123 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,123 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 3570
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"/>
  7.     <xsl:choose>
  8.       <xsl:when test="contains($text, $from)">
  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)"/>
  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>
Jan 28 '08 #2
i still can'not understand ....
Jan 29 '08 #3
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>
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

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.