xsl-list
[Top] [All Lists]

Encoding Issues with JavaScript in CDATA Element

2005-05-25 18:20:35
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)",
"('10° F or below', 'L_Synth_10')",
"('15° F to 32° F', 'L_Synth_15')",
"('35° 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)",
"('10° F or below', 'L_Synth_10')",
"('15° F to 32° F', 'L_Synth_15')",
"('35° 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>