Re: GOTCHA!

Subject: Re: GOTCHA!
From: James Clark <jjc@xxxxxxxxxx>
Date: Fri, 15 Jan 1999 09:23:02 +0700
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