Escape
Escape single or double quotes
Browse
Description
Escape single or double quotes in a string. This is ideal if you're using the content to use in JavaScript strings.
XSLT
View Raw
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str"> <!-- Escape single or double quotes in a string. This is ideal if you're using the content to use in JavaScript strings. Usage: <xsl:call-template name="escape-single-quotes"> <xsl:with-param name="text" select="my-content" /> </xsl:call-template> <xsl:call-template name="escape-double-quotes"> <xsl:with-param name="text" select="my-content" /> </xsl:call-template> --> <!-- Escape single quotes --> <xsl:template name="escape-single-quotes"> <xsl:param name="text" /> <xsl:variable name="apos">'</xsl:variable> <xsl:variable name="bapos">\'</xsl:variable> <xsl:value-of select="str:replace($text, $apos, $bapos)" /> </xsl:template> <!-- Escape double quotes --> <xsl:template name="escape-double-quotes"> <xsl:param name="text" /> <xsl:variable name="apos">"</xsl:variable> <xsl:variable name="bapos">\"</xsl:variable> <xsl:value-of select="str:replace($text, $apos, $bapos)" /> </xsl:template> </xsl:stylesheet>