Tuesday, 27 April 2010

Escaping javascript strings in Umbraco XSLT macros

How to escape string literals in XSLT which appear inside JavaScript function calls:-

<xsl:variable name="apos">'</xsl:variable>
<xsl:if test="data[@alias='popupMessage'] != ''">
      <xsl:attribute name="onclick">
        <xsl:text>return window.confirm('</xsl:text>
        <xsl:value-of select="umbraco.library:Replace(data[@alias='popupMessage'], $apos, concat('\',$apos))" disable-output-escaping="yes" />
        <xsl:text>');</xsl:text>
      </xsl:attribute>
</xsl:if>