[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

passing the an apostrophe as a string to a param.

Subject: passing the an apostrophe as a string to a param.
From: Adam Van Den Hoven <Adam.Hoven@xxxxxxxxxxxx>
Date: Wed, 11 Apr 2001 09:17:16 -0700
passing apostrophe in javascript
I have a named template that simply looks for all the instances of a
character in a string and adds a backslash to them so that the resulting
string, which ends up in javascript will be correctly interpreted. I needed
to convert the \ which appeared in a path into \\ so that javascript would
interpret the string correctly.

No I need to escape the apostrophes. Right now I'm generating the following
HTML:
<a href="javascript:ShowClip('/clip.rm', 'Hijacking ends safely',
38804);">...</a>

which is fine until I need to write out:
<a href="javascript:ShowClip('/video/2001/02/20/7464SN.rm', 'Third day's the
charm for Atlantis? 0:34', 46031);">

what I want is
<a href="javascript:ShowClip('/video/2001/02/20/7464SN.rm', 'Third day\'s
the charm for Atlantis? 0:34', 46031);">


Currently I use the following template:

<xsl:template name="SlashChars">	
	<xsl:param name="content" />
	<xsl:param name="char" />
	
	<xsl:variable name="before"
select="normalize-space(substring-before($content, $char))" />
	<xsl:variable name="after"
select="normalize-space(substring-after($content, $char))" />
	<xsl:choose>
		<xsl:when test="contains($content, $char)" ><xsl:value-of
select="$before" />\<xsl:value-of select="$char" /><xsl:call-template
name="SlashChars">
				<xsl:with-param name="content"
select="$after" />
				<xsl:with-param name="char" select="$char"
/>
			</xsl:call-template></xsl:when>
		<xsl:otherwise><xsl:value-of select="$content"
/></xsl:otherwise>
	</xsl:choose>
</xsl:template>

> Which I call using to correct my clip URLS with:
<xsl:call-template name="SlashChars">
	<xsl:with-param name="content" select="@ClipURL" />
	<xsl:with-param name="char" select="'\'" />
</xsl:call-template>

but how do I do it for my captions?
<xsl:call-template name="SlashChars">
	<xsl:with-param name="content" select="@Caption" />
	<xsl:with-param name="char" select="''''" /> <!-- thats four ' in  a
row within " -->
</xsl:call-template>


> I am stumped.
> 
> Or if someone has a better solution to this, I'm all ears.
> 
> Adam van den Hoven
> Internet Application Developer
> Blue Zone
> tel. 604.685.4310
> fax. 604.685.4391
> Blue Zone makes you interactive.(tm) http://www.bluezone.net/
> 

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.