Replacing text in XSL, the dirty way


Here the example replaces quotes with escaped quotes \”, but can be generalized.

First define a template:

<xsl:template name="cleanQuote">
<xsl:param name="string" />
<xsl:if test="contains($string, '"')">
<xsl:value-of select="substring-before($string, '"')" /> \"
<xsl:call-template name="cleanQuote">
<xsl:with-param name="string">
<xsl:value-of select="substring-after($string, '"')" />
<xsl:if test="not(contains($string, '"'))">
<xsl:value-of select="$string" />

Then use it at the appropriate point by calling:

<xsl:call-template name="cleanQuote">
<xsl:with-param name="string">
<xsl:value-of select="text" />


One Response to “Replacing text in XSL, the dirty way”

  1. Zaiya Says:

    This forum needed shniakg up and you’ve just done that. Great post!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: