A revised version of XHTML 1.0 has been released. I've never understood why Script and Style elements are #PCDATA instead of #CDATA. I'd love to hear the reasoning behind that.
Also see this HTML compatibiltiy note on Embedded Style Sheets and Scripts.
Use external style sheets if your style sheet uses < or & or ]]> or --. Use external scripts if your script uses < or & or ]]> or --. Note that XML parsers are permitted to silently remove the contents of comments. Therefore, the historical practice of "hiding" scripts and style sheets within "comments" to make the documents backward compatible is likely to not work as expected in XML-based user agents.
How annoying is that? You're supposed to use external scripts if your script contains a less than character or an ampersand, which we all know rarely if ever turn up in programming. Asses.
You're really supposed to escape the contents of any embedded script with <![CDATA[ .. ]], but as I discovered, that doesn't seem to work in browsers (which is probably why they just tell you to use an external script or stylesheet). Here's my workaround to make my pages with scripts validate: I use the <![CDATA[ crap, but I put it inside JavaScript comments like so:
<script type="text/javascript">
//<![CDATA[
... script goes here ...
//]]>
</script>
This way it validates, and it's totally valid, but doesn't screw up user-agents which don't support the <![CDATA[ crap (and none currently do, AFAIK). Also, this is different than the script "hiding" with HTML comments they mentioned in the quote above. HTML comments aren't valid in JavaScript, but this trick uses JavaScript comments, so there's no problem, nor will there ever be.
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):