[xsl] Escaping apostrophes for use in javascript, etc. - how to trouble shoot template results?

Subject: [xsl] Escaping apostrophes for use in javascript, etc. - how to trouble shoot template results?
From: "Kathy Burke" <Kathy_Burke@xxxxxxxxx>
Date: Thu, 9 Oct 2003 08:41:36 -0400
Can't believe I forgot to include Jeni's template:

<xsl:template name="escape-apos"> 
<xsl:param name="string" />
 <!-- create an $apos variable to make it easier to refer to -->
 <xsl:variable name="apos" select='"&apos;"' /> 
<xsl:choose> 
<!-- if the string contains an apostrophe... --> 
<xsl:when test='contains($string, $apos)'> 
<!-- ... give the value before the apostrophe... -->
 <xsl:value-of select="substring-before($string, $apos)" />
 <!-- ... the escaped apostrophe ... --> 
<xsl:text>\'</xsl:text>
 <!-- ... and the result of applying the template to the string after the
apostrophe -->
 <xsl:call-template name="escape-apos">
 <xsl:with-param name="string" select="substring-after($string, $apos)" />
 </xsl:call-template>
 </xsl:when> 
<!-- otherwise... -->
 <xsl:otherwise> 
<!-- ... just give the value of the string -->
 <xsl:value-of select="$string" /> 
</xsl:otherwise> 
</xsl:choose> 
</xsl:template> 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread