[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Content of Script element getting wrapped by CDATA

Subject: Re: Content of Script element getting wrapped by CDATA
From: "Darcy Parker" <darcyparker@xxxxxxxxx>
Date: Thu, 23 Oct 2008 10:56:30 -0400
Re:  Content of Script element getting wrapped by CDATA
> It does seem complicated to hide the CDATA section... but it is
> necessary if you have invalid XML characters in your javascript code
> and do not wish to escape them individually.
>
> No, XSLT would do this automatically, doing it differently in xml or
> html output.

This took me a bit to get:

If output is set to html and remove the script template, then XSLT
(saxon at least) does not escape the output.  I still need to escape
the input or enclose it in a CDATA so that the input is well formed
XML. But the output is unescaped as required.  So I now understand
what you meant by not using the CDATA in the output. (One limitation
may be that you can't process it as XML again because the output
content is not escaped.... unless you happen to have an easy way to
convert the HTML back to well formed XML.  Or have an XSLT processor
that can use an HTML parser.)

But if the output is set to XML, then it does seem necessary to use a
javascript comment on the CDATA because even though the output is set
to strict XHTML, the browser I tried (firefox) doesn't seem to
understand CDATA in the script element.  Hence the complicated
workaround of putting a javascript comment in front of the CDATA.  I
wished browsers would just understand CDATA when the doctype is xhtml
(ie XML).

So I like the idea of just not using the CDATA and using html output
(even if doctype is set to XHTML). But it still seems to have some
weaknesses.

This seems to be a common question over the years.  And there is lots
of advice to be found in books like Jeni Tennison's Beginning XSLT,
and of course google.  But after experimenting and understanding your
comment, I still feel unsatisfied with the possible solutions for
inline javascript. (Moving the javascript to an external file as
Andrew mentioned seems to be ideal.) Can anyone recommend a good
article that compares/contrasts techniques for dealing with inline
javascript in XML documents - such that most browsers can interpret
it?

Darcy

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.