String Replace

Language:
XSLT
Keywords:
XSLT
Code Snippet

<xsl:template name="string-replace">
  <xsl:param name="text" />
  <xsl:param name="replace" />
  <xsl:param name="with" />

  <xsl:choose>
    <xsl:when test="contains($text, $replace)">
      <xsl:value-of select="substring-before($text, $replace)" />
      <xsl:value-of select="$with" />
      <xsl:call-template name="string-replace">
        <xsl:with-param name="text" select="substring-after($text, $replace)" />
        <xsl:with-param name="replace" select="$replace" />
        <xsl:with-param name="with" select="$with" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


Created 2012-02-01
comments powered by Disqus
Login