[xquery-talk] Getting a bare & and > into HTML for Javascript

David Lee dlee at calldei.com
Wed Jul 20 09:01:46 PDT 2011

Thanks, I will try this.
I am using html tag but in the xhtml namespace ...

<html xmlns="http://www.w3.org/1999/xhtml">

But in the script tag its obviously not expanding the &

I will try the CDATA trick.

David A. Lee
dlee at calldei.com

-----Original Message-----
From: Ghislain Fourny [mailto:gfourny at inf.ethz.ch] 
Sent: Wednesday, July 20, 2011 11:58 AM
To: David Lee
Cc: <talk at x-query.com>
Subject: Re: [xquery-talk] Getting a bare & and > into HTML for Javascript

Hi David,

I am assuming you are using HTML, not XHTML, since if I am correct, XHTML
would recognize the & entity reference. In HTML, entity references in
the script tag are not parsed. In XHTML they are.

I guess a possibility could be to use a CDATA section that is ignored by
JavaScript, like so (in your XQuery code):

<script type="text/javascript">
// <cdata-section><![CDATA[
(: code generation here :)
// ]]></cdata-section>

and to tell the XQuery engine to serialize the contents of the element
<cdata-section/> using a CDATA section, using the cdata-section-elements XML
output method:


That way, JavaScript would see the intended code - you need to make sure
that ]]> does not appear in your JavaScript code though, otherwise there
will be extra CDATA tags that the browser will not understand.

Does this help?

Kind regards,

More information about the talk mailing list