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

Ghislain Fourny gfourny at inf.ethz.ch
Wed Jul 20 08:58:07 PDT 2011


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