« XSLT to strip HTML tags | Home | XSLT to replace substring »

XSLT to escape single quotes and double quotes

<!--
 This template is used to escape the ' and " in text nodes that need
 to be assigned to javascript string variables. It replaces them with
 the javascript-standard \' and \"
-->

<xsl:template name="common_js_escape">
<!-- required -->
<xsl:param name="text"/>
<xsl:variable name="tmp">

<xsl:call-template name="replace-substring">
<xsl:with-param name="from" select="'&quot;'"/>
<xsl:with-param name="to">\"</xsl:with-param>
<xsl:with-param name="value">
<xsl:call-template name="replace-substring">
<xsl:with-param name="from">&apos;</xsl:with-param>
<xsl:with-param name="to">\'</xsl:with-param>
<xsl:with-param name="value" select="$text" />
</xsl:variable>
<xsl:value-of select="$tmp" />
</xsl:template>

Topics: XSLT | Submitter: admin

Comments

You must be logged in to post a comment.

Keep on coding