Author:
TwistedInteractive
Version:
0.1
Release Date:
30 Nov 2010
Category:
String Operations

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>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details