Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2008, 08:22 PM
Authorized User
 
Join Date: Jan 2007
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

 
Old January 23rd, 2008, 04:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old January 23rd, 2008, 01:12 PM
Authorized User
 
Join Date: Jan 2007
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

 
Old January 23rd, 2008, 01:30 PM
Authorized User
 
Join Date: Jan 2007
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

 
Old January 23rd, 2008, 01:35 PM
Authorized User
 
Join Date: Jan 2007
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>
 
Old January 23rd, 2008, 01:56 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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>





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 11:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.