Unicode (UTF-16) question

R

Rob Cox

Hi (xsl novice here),

I have a file called myResources.xml that contains some strings that
will be localized.

In myXSL.xsl file, I read the strings from here to output as html.
myXSL.xsl is saved as UTF16.

myResources.xml is currently saved as ASCII.

Things work fine now.

But...when I change myResources.xml and save it as UTF16 (and put the
proper header <?xml version="1.0" encoding="UTF-16"?> at the top),
then things don't work any more.

The html that is generated is missing the strings that were supposed
to be substituted from myResources.xml.

It worked as ascii, but when I saved/switched myResources.xml to
UTF16, the substitutions stopped working.

myXSL.xsl is doing something like this:

<stuff deleted>

<xsl:variable name="translationsFile" select="concat($webRoot,
'/xsl/','myResources.xml')"/>
<xsl:variable name="translations"
select="document($translationsFile)"/>
<xsl:param name="isolang" select="'en'"/>

<xsl:variable name="reportTitleText">
<xsl:choose>
<xsl:when test="count($translations/LocalizedResources/resource[lang($isolang)]/displayText[@category='REPORT_TITLE'])
&gt; 0">
<xsl:copy-of select="$translations/LocalizedResources/resource[lang($isolang)]/displayText[@category='REPORT_TITLE']"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:text>My Default Report String</xsl:text>
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>


--------------
myResources.xml snippet below
<resource xml:lang="en">
<!-- Resources for viewing a report -->
<displayText category="REPORT_TITLE">Final Report</displayText>
etc.
 
M

Marrow

Hi Rob,

It sounds as though when you are saving myResources.xml as UTF-16 it isn't
actually being encoded properly as UTF-16. Have you checked that document
loads and parses after saving it?

Depending on your transformation engine - this might explain why the
document() function is apparently bringing back nothing.
(http://www.w3.org/TR/xslt#document - in particular "If there is an error in
processing the fragment identifier, the XSLT processor may signal the error;
if it does not signal the error, it must recover by returning an empty
node-set."). In other words, if the document() function is failing to load
the document because it is improperly encoded then it may be just returning
an empty node-set - which might explain the behaviour you are seeing.

Cheers
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
 
A

Alan J. Flavell

Use UTF-8 instead of UTF-16 - especially when your final goal is HTML.
UTF-16 isn't currently a good idea for HTML.

As far as what is served-out to the web is concerned, I would agree
with you...

But to some extent it's the hon Usenaut's own private affair how they
choose to store their data internally, if they have a good way to
recode it into an appropriate form for serving out to the web.

Well, that page aims specifically at the use of HTML served as
text/html in a WWW context for browsing with HTML-ish browsers.

There's a brief note about XHTML/1.0 served out under Appendix C,
but I don't go any more-deeply into XML issues. It'd be interesting,
seeing that we're on an XML group, if XML practitioners would care
to review it and see how it matches their own views of the
practicalities.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top