Skip to content

Instantly share code, notes, and snippets.

@jlafitte
Created July 13, 2012 23:57
Show Gist options
  • Save jlafitte/3108313 to your computer and use it in GitHub Desktop.
Save jlafitte/3108313 to your computer and use it in GitHub Desktop.
A replace-all XSL template. Very useful if you are stuck in XSLT 1.0 world, but made obsolete in XSLT 2.0+
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment