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

Re: Escaping an apostrophe for JavaScript

Subject: Re: Escaping an apostrophe for JavaScript
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Sat, 24 Feb 2001 23:42:35 -0800
using apostrophe in javascript
here you go:


<xsl:template name="fixquotes">
   <xsl:param name="string"/>
    <xsl:choose>
      <xsl:when test="contains($string, &quot;'&quot;)">
        <xsl:value-of select="substring-before($string, &quot;'&quot;)"/>
        <xsl:text>\'</xsl:text>
        <xsl:call-template name="fixquotes">
          <xsl:with-param name="string"
            select="substring-after($string, &quot;'&quot;)"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string"/>
      </xsl:otherwise>
    </xsl:choose>
</xsl:template>


----- Original Message ----- 
From: "Frank T. O'Connor" <foconnor@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, February 24, 2001 6:44 PM
Subject:  Escaping an apostrophe for JavaScript


> Using MSXML3.
> 
> Trying to write the following string:
>   <img 
>     src="blah.gif" 
>     onMouseOver="window.status='Frank O\'Connor'; return true;"
>   />
> 
> The problem is my source XML doesn't have the apostrophe escaped for
> javascrpt. The source node simply has "O'Connor" in it.
> I can't seem to figure out any way of using translate or substring to
> convert the apostrophe to a backslash-apostrophe. There doesn't seem to
> be any way to locate the location of a substring within a string. Unless
> I loop it one character at a time.
> 
> I was thinking perhaps I could make up a entity that is
> backslash-apostrophe, and then tell translate to replace apostrophe with
> this entity.
> 
> But I'm not sure where to put this DTD information in my XSL file. 
> 
> I tried this:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE xsl:stylesheet [
> <!ENTITY test "\&apos;">
> ]>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> ...
> </xsl:stylesheet>
> 
> but I get this error:
> The element 'xsl:stylesheet' is used but not declared in the DTD/Schema
> 
> 
> any suggestion?
> 
> Thanks,
> -frank
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 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.