Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 22nd, 2008, 07:22 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default escape double quote inside JavaScript

I am using output method="html" and trying to print a block of JavaScript. This JavaScript has an array variable that I need to place escaped HTML inside. Namely, XSLT chokes when I use a backslash character within my JavaScript variable. Here's a simplified version of my JavaScript that's inside my XSLT:

Code:
<script language="JavaScript1.2"  type="text/javascript">
  Text[0]=["<div style=\"padding:3px\">Dr. John Doe</div>"];
</script>
I've tried single quotes instead of \" but it doesn't work. I also tried using &lt; and &gt; but it doesn't work either because of how JavaScript handles things. Any ideas on how I can escape my double quotes inside JavaScript?

Thanks,
Steve

Reply With Quote
  #2 (permalink)  
Old January 23rd, 2008, 03:46 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

It's not XSLT that's choking on your stylesheet, it's XML. Remember that an XSLT stylesheet has to be a well-formed XML document, and the way you escape a double quote within an attribute value is "&quot;".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old January 23rd, 2008, 12:12 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've tried using a &quot; character but still to no avail:

Code:
Text[0]=["<div style=&quot;padding:3px&quot;>Dr. John Doe</div>"];
Is there a way I can somehow use <xsl:text> to just ignore all XML markup and simply output any sort of text I want?

Steve

Reply With Quote
  #4 (permalink)  
Old January 23rd, 2008, 12:30 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just got it to work by doing this:

Code:
Text[0]=["&lt;div style=\"padding:3px\">Dr. John Doe&lt;/div>"];
Thanks for the help though.
Steve

Reply With Quote
  #5 (permalink)  
Old January 23rd, 2008, 12:35 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, and I wrapped it in an <xsl:comment>

Code:
<script language="JavaScript1.2"  type="text/javascript">
  <xsl:comment>
    Text[0]=["&lt;div style=\"padding:3px\">Dr. John Doe&lt;/div>"];
  </xsl:comment>
</script>
Reply With Quote
  #6 (permalink)  
Old January 23rd, 2008, 12:56 PM
Friend of Wrox
Points: 6,522, Level: 34
Points: 6,522, Level: 34 Points: 6,522, Level: 34 Points: 6,522, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,220
Thanks: 0
Thanked 237 Times in 236 Posts
Default

You could use a CDATA section in your stylesheet to wrap JavaScript code:
Code:
<script type="text/javascript"><![CDATA[
  Text[0]=["<div style=\"padding:3px\">Dr. John Doe<\/div>"];
]]></script>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i get rid off the double quote in a text myer75 VBScript 7 April 14th, 2009 07:11 PM
javascript in CDATA doesnt escape html eruditionist XSLT 5 September 17th, 2008 01:07 PM
Single quote in function Parameter ASP -Javascript Hem96 Classic ASP Professional 4 September 14th, 2007 09:10 AM
escape character for double quotes Andy dg C# 2005 3 March 15th, 2007 10:51 PM
Showing single and double quote in text field. ggriffit SQL Server ASP 4 January 5th, 2004 10:19 AM



All times are GMT -4. The time now is 01:21 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.