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

Ghislain Fourny gfourny at inf.ethz.ch
Wed Jul 20 09:19:20 PDT 2011

Hi David,

In the current state of HTML5 as I understand it, there are two syntaxes: HTML and XHTML. Using the xmlns="http://www.w3.org/1999/xhtml" attribute in the HTML syntax is allowed but has no effect (more here: http://www.w3.org/TR/html5/elements.html#global-attributes).

An HTML parser will not expand & in script tags. As Michael suggests, using the HTML output method is the cleanest way to provide an HTML parser with the right syntax. That way, the XQuery engine will not escape & to & in script tags (quoting from the serialization specification: "The HTML output method MUST NOT perform escaping for the content of the script and style elements.").

I hope this helps.

Kind regards,

On Jul 20, 2011, at 6:01 PM, David Lee wrote:

> 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
> http://www.xmlsh.org
> -----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>
> </script>
> 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:
> http://www.w3.org/TR/xslt-xquery-serialization/#XML_CDATA-SECTION-ELEMENTS
> 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,
> Ghislain

More information about the talk mailing list