XSTL and ISO-8859-1 encoding, Regional char gets scrambled

Here should go questions about transforming XML with XSLT and FOP.
erikhedb
Posts: 4
Joined: Wed Dec 12, 2007 11:06 am

XSTL and ISO-8859-1 encoding, Regional char gets scrambled

Post by erikhedb »

Dear Sir / Madam,

I have a problem when I XSLT:to encoding=ISO-8859-1.

The regional characters ÅÄÖ gets turned info AG;≈ƒ÷ ‰.

When I set output to:

<xsl:output encoding="UTF-16" method="text"/>

The characters turn out fine.

Also I have found that it does not matter what encoding i use on the source file. I did try both UTF-16 and ISO-8859-1.

Ideas anyone?

Thanx /Erik
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

I just tested a simple transformation of an input XML file containing the characters ÅÄÖ. These characters are preserved in the output with any combination between output method "text" or "xml", output encoding UTF-8 or ISO-8859-1 and input encoding UTF-8 or ISO-8859-1 for the XML file containing the characters. I used Saxon 6.5. Can you post a simple XML file and a simple XSLT stylesheet for reproducing the problem?


Regards,
Sorin
erikhedb
Posts: 4
Joined: Wed Dec 12, 2007 11:06 am

Sample XML

Post by erikhedb »

Thanx for fast answers:

1. source.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<test xmlns="testSpace">
<text>REFERENCE TEXT</text>
<text>Ã¥</text>
<text>ä</text>
<text>ö</text>
<text>Ã…</text>
<text>Ä</text>
<text>Ö</text>
</test>

2. Tranformer.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SourceNS="testSpace"
version="2.0">
<xsl:output encoding="ISO-8859-1" method="text"/>
<xsl:template match="SourceNS:test">
<xsl:text>Char:</xsl:text><xsl:value-of select="./SourceNS:text"/>
</xsl:template>
</xsl:stylesheet>

3. output.txt
Char:REFERENCE TEXT � � � � � �

Also I just found that the file look correct on a windows machine but not on my Mac using Oxygen 8.2.

Any idea?
erikhedb
Posts: 4
Joined: Wed Dec 12, 2007 11:06 am

Also

Post by erikhedb »

In the editor window i get the funny carchters but in the "imidiate" window at the bottom I get correct characters.

/erik
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

I set ISO-8859-1 as encoding for non XML files in preferences, I set a a text file name (test.txt) in the transformation scenario as the transformation result (because you have method="text" in your XSLT stylesheet) and I applied your stylesheet to your XML sample file. I obtained the following output both in the file test.txt and in the XML view panel at the bottom of the oXygen window:

Code: Select all


Char:REFERENCE TEXT å ä ö Å Ä Ö
What is the name of the output file that you set in the scenario and what is the encoding for non XML files set in Options -> Preferences -> Global -- Encoding for non XML files? If you save the result in an .xml file the encoding used to try to open the file is the default one, that is UTF-8 because your result file does not declare any explicit encoding with a declaration like:

Code: Select all


<?xml version="1.0" encoding="ISO-8859-1"?>
The result file cannot be read correctly with UTF-8 and the effect is that you see "funny characters" when the encoding error policy is set to REPLACE or you get an error message that the file cannot be opened with the UTF-8 encoding when the encoding error policy is set to REPORT. You can change the encoding error policy in Options -> Preferences -> Global -- Encoding errors handling.


Regards,
Sorin
erikhedb
Posts: 4
Joined: Wed Dec 12, 2007 11:06 am

Works like a charm

Post by erikhedb »

Yes . did as you suggested and it works perfect. Thanks for quick response.
Post Reply