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

Michael Kay mike at saxonica.com
Wed Jul 20 09:20:40 PDT 2011


On 20/07/2011 17:01, 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&

Don't use the XHTML namespace if you're trying to serialize as HTML. 
Generally most of the special tricks used by an HTML serializer work 
only on elements that are in no namespace.

Michael Kay
Saxonica

> 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
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
>



More information about the talk mailing list