[xsl] Encoding Issues with JavaScript in CDATA Element

Subject: [xsl] Encoding Issues with JavaScript in CDATA Element
From: "Brook Ellingwood" <belling@xxxxxxx>
Date: Wed, 25 May 2005 18:20:35 -0700
I have an existing HTML page with a JavaScript in it that includes a variable
that uses the UTF-8 character for the "degree" sign:

var Array_L_Synth = new Array(
//"(Opts[2], 'ChooseTemp', true, true)",
"(fieldSpacer, 'ChooseTemp', true, true)",
"('100 F or below', 'L_Synth_10')",
"('150 F to 320 F', 'L_Synth_15')",
"('350 F and above', 'L_Synth_35')"
);

This page has no problems.

I copied the JavaScript into a CDATA element in an XML file:

<script><![CDATA[
 <script type="text/javascript">
...
 ]]></script>
</script>

I applied this template:

<xsl:template match="script">
 <xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>

I'm using XMLSpy/MSXML 3. IE displays the output fine, but Firefox and Opera
both have problems with the "degree" character, and the source shows the
problem as well:

var Array_L_Synth = new Array(
//"(Opts[2], 'ChooseTemp', true, true)",
"(fieldSpacer, 'ChooseTemp', true, true)",
"('10B0 F or below', 'L_Synth_10')",
"('15B0 F to 32B0 F', 'L_Synth_15')",
"('35B0 F and above', 'L_Synth_35')"
);

If I manually change the browser encoding from ISO-8859-1 to UTF-8, the
problem resolves itself. However if I go to the orinal HTML (which displays
fine) and change the browser encoding to UTF-8, the properly rendered "degree"
signs turn into "?".

I can't figure this one out. Any ideas?

I'm using the exact same XML/XSL on two other JavaScripts that don't have any
problems. It's not impossible for me to make this an external .js file if that
will solve the problem, but I don't know if that will fix it and I'm
interested in understanding what's going wrong.

Thanks,
-- Brook

Current Thread