Replacing text in XSL, the dirty way

by

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:with-param>
</xsl:call-template>
</xsl:if>
<xsl:if test="not(contains($string, '"'))">
<xsl:value-of select="$string" />
</xsl:if>
</xsl:template>

Then use it at the appropriate point by calling:


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

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: