[xsl] Original encoding lost after transformation

Subject: [xsl] Original encoding lost after transformation
From: guray@xxxxxxxxxxxxxxxxxxxx
Date: Fri, 18 Feb 2005 12:02:38 +0100
Hi list,

I seem to have an encoding problem with my xsl transformations. I'm
trying to transform incoming xml data using two stylesheets.

The incoming xml has the ISO-8859-1 encoding. Its declaration is like

<?xml version="1.0" encoding="ISO-8859-1"?>

I then apply two consecutive xsl transformation to it. The problem is
that after the transformations, the output is in the UTF-8 encoding. The
declaration is then like this:

<?xml version="1.0" encoding="UTF-8"?>

Some transformations (depending on the source xml) now fail on the
second pass as the first pass returns data with the wrong UTF-8 declaration
above. The error message is:

java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 sequence

This is the stylesheet that does the first transformation (sorting all

<?xml version="1.0" encoding="UTF-8">
<xsl:stylesheet version="1.0"
	<xsl:template match="@* | node()">
			<xsl:apply-templates select="@* | node()">
				<xsl:sort select="name()"/>

I tried setting the xsl:output method as this, but to no avail:

<xsl:output method="xml" version="1.0" encoding="ISO-8859-1"/>

What can be wrong? Why is the encoding changed after the transformation?

Any insight greatly appreciated,

Current Thread