Re: [xsl] character encoding in xsl [forced]

Subject: Re: [xsl] character encoding in xsl [forced]
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 2 Dec 2002 15:53:10 -0700 (MST)
Mac Rost wrote:
> I am having a pblm with the character encoding of a nbsp; in my xsl.

You have 2 problems, actually.

> When the html transformation is done, each nbsp; comes out as a ?.

This is problem #1. If you ever see a character replaced with "?", it means
that you tried to serialize it in an encoding that did not have a byte
sequence available to represent that character. If it's a no-break space,
which is Unicode character #160 (#xA0), the most likely cause is that you were
trying to encode it as us-ascii, which only covers Unicode characters #0-#127.

I suspect that this problem is unrelated to the second problem.

> Now when the transformation is finished, the encoding is set to utf-16.
> Is there a way to force a different encoding?

Problem #2. In general, you can tell the XSLT processor what encoding to use
*if* it is serializing the output via the encoding attribute of the xsl:output
element. That is, use <xsl:output method="..." encoding="utf-8"/> in your
stylesheet.

Ensure that the input to the XSLT processor (both XML and XSLT) are either
Unicode text or encoded text with an accurate encoding declaration in their 
XML prologs.

If the result is being serialized as encoded text, ensure that the xsl:output
instruction tells the XSLT processor what encoding you want it to use.

Ensure that the result of the transformation is not being coerced to a
different encoding (UTF-16, it seems) when you pass it around within your
application. For example, if you're getting a Microsoft DOM object as the
result, and you're capturing it in a String object, you'll get UTF-16 during
the implicit conversion. If you're using MSXML and think this might be
happening, do a Google search for MSXML UTF-16 and you'll find the answer.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

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


Current Thread