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

Re: ESCAPE SINGLE QUOTES FOR JAVASCRIPT PARAMETER IN X

Subject: Re: ESCAPE SINGLE QUOTES FOR JAVASCRIPT PARAMETER IN XSLT
From: Cleyton Jordan <cleytonjordan@xxxxxxxxxxx>
Date: Fri, 6 Jun 2008 23:35:51 +0000 (GMT)
Re:  ESCAPE SINGLE QUOTES FOR JAVASCRIPT PARAMETER IN X
Hi Martin,

Many thanks for your reply.

I use XSLT 1.0. So the function you provided will not work for me.

Is there any similar trick in XSLT 1.0?

Cheers

Claudio

------------
Date: Thu, 05 Jun 2008 13:52:40 +0200
To:  xsl-list@xxxxxxxxxxxxxxxxxxxxxx
From: Martin Honnen <Martin.Honnen@xxxxxx>
Subject: Re:  ESCAPE SINGLE QUOTES FOR JAVASCRIPT PARAMETER IN XSLT
Message-ID: <4847D388.4040900@xxxxxx>

Cleyton Jordan wrote:

> <A AR="I Don't Watch It" AID="768564" APID="76158" AC="5"/>
>
> As you can see the value of the @AR attribute has a single quote. This is
causing me a lot of problems when I use xslt to call a javascript function
passing the parameters.
>
> I was wondering if someone could help me to find a solution for that.

Do you use XSLT 2.0 or 1.0?

--

    Martin Honnen
    http://JavaScript.FAQTs.com/

------------------------------

Date: Thu, 05 Jun 2008 17:45:31 +0200
To:  xsl-list@xxxxxxxxxxxxxxxxxxxxxx
From: Martin Honnen <Martin.Honnen@xxxxxx>
Subject: Re:  ESCAPE SINGLE QUOTES FOR JAVASCRIPT PARAMETER IN XSLT
Message-ID: <48480A1B.7070305@xxxxxx>

Cleyton Jordan wrote:

> <A AR="I Don't Watch It" AID="768564" APID="76158" AC="5"/>
>
> As you can see the value of the @AR attribute has a single quote. This is
causing me a lot of problems when I use xslt to call a javascript function
passing the parameters.
>
> I was wondering if someone could help me to find a solution for that.

Here is an XSLT 2.0 function that escapes four characters as needed for
JavaScript string literals:

   <xsl:function name="my:escape" as="xs:string">
     <xsl:param name="s" as="xs:string"/>
     <xsl:sequence
       select="replace(
                 replace(
                   replace(
                     replace($s, &quot;'&quot;, &quot;\\'&quot;),
                     '&quot;',
                     '\\&quot;'
                   ),
                   '\r',
                   '\\r'
                 ),
                 '\n',
                 '\\n'
               )"/>
   </xsl:function>

You can the use it as e.g.
   '<xsl:value-of select="my:escape(@AR)"/>'

--

    Martin Honnen
    http://JavaScript.FAQTs.com/

------------------------------



      __________________________________________________________
Sent from
Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

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.