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

Re: GOTCHA!

Subject: Re: GOTCHA!
From: James Clark <jjc@xxxxxxxxxx>
Date: Fri, 15 Jan 1999 09:23:02 +0700
gotcha hacks
Oren Ben-Kiki wrote:
> 
> James Clark <jjc@xxxxxxxxxx> wrote:

> there's already a hack you can use to avoid
> >that problem, which is to use a PI:
> >
> ><script>//<xsl:pi name="xyzzy">
> >for(i = 10; i >= 0; i--) {
> >}
> >//</xsl:pi></script>
> 
> Now this is a hack! You stepped on another XT bug here - or a specs bug. I
> checked the following:
> 
> <xsl:template match="A">
> <xsl:pi name="JavaScript">
>  <xsl:text><![CDATA[<&>]]></xsl:text></xsl:pi>
> </xsl:template>
> 
> And got in the result:
> 
> <?JavaScript <&>>

Not an XT bug or a specs bug. You would get

<?JavaScript <&>?>

which *is* well-formed. Remember that in XML a PI is terminated by ?>.
How often will you get ?> in Javascript? Less often than ]]> I suspect.

> Or could I expect that an XML/XSL processor to be smart enough to use
> different character quoting rules within a <SCRIPT> tag?

Right.

> It would also have
> to examine the LANGUAGE attribute for it... 

Huh? SCRIPT in HTML 4.0 is an SGML CDATA element, which means that whe
outputting it, & and < must not be escaped to &amp; and &lt;.  This is
independent of the scripting language.

> I'd be very surprised if this
> works - it certainly doesn't in XT.

It works just fine in XT.  For example, given this:

<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/TR/WD-xsl"
 xmlns="http://www.w3.org/TR/REC-html40"
 result-ns="">

<xsl:template match="/">

<script><![CDATA[
document.write("<P>Hi Oren");
]]></script>

</xsl:template>

</xsl:stylesheet>

XT will output:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script>
document.write("<P>Hi Oren");
</script>

It would output the same from:

<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/TR/WD-xsl"
 xmlns="http://www.w3.org/TR/REC-html40"
 result-ns="">

<xsl:template match="/">

<script>
document.write("&lt;P&gt;Hi Oren");
</script>

</xsl:template>

</xsl:stylesheet>

XT knows that in HTML 4.0 SCRIPT and STYLE are CDATA elements and that <
and & shouldn't be escaped inside them.  This is a much cleaner solution
than all these silly hacks with comments and PIs, and it is already in
the XSL spec (see section 2.2).

In summary, the existing spec already provides two solutions to the
problem, which seems more than enough, especially given that the problem
won't exist in the long term.

James



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.