Re: replacing characters in a string

Subject: Re: replacing characters in a string
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 15 Oct 1999 13:33:02 +0100 (BST)
>  see if there's an apostrophe character, if so, convert this
> to \', if not, just output the value of 'name'.


something like this?

David

  <xsl:call-template name="string-replace">
    <xsl:with-param name="from" select="'&apos;'"/>
    <xsl:with-param name="to" select="'\&apos;'"/> 
    <xsl:with-param name="string" select="."/>
  </xsl:call-template>


<!-- replace all occurences of the character(s) `from'
     by the string `to' in the string `string'.-->
<xsl:template name="string-replace" >
  <xsl:param name="string"/>
  <xsl:param name="from"/>
  <xsl:param name="to"/>
  <xsl:choose>
    <xsl:when test="contains($string,$from)">
      <xsl:value-of select="substring-before($string,$from)"/>
      <xsl:value-of select="$to"/>
      <xsl:call-template name="string-replace">
      <xsl:with-param name="string" select="substring-after($string,$from)"/>
      <xsl:with-param name="from" select="$from"/>
      <xsl:with-param name="to" select="$to"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread