XSL transformation: utf-8 and iso-8859-1 compatibility
<p>I use .NET class XslCompiledTransform for xslt transformation and I have a problem with encodings. I have this word <strong>Förstelärare</strong> in my input xml. Here is cases:</p>

<ol>
<li>input xml file has <code>&lt;?xml version="1.0" encoding="utf-8"?&gt;</code> - xslt file has <code>&lt;xsl:output encoding="utf-8" ...</code> - <strong>OK</strong></li>
<li>input xml file has <code>&lt;?xml version="1.0" encoding="utf-8"?&gt;</code> - xslt file has <code>&lt;xsl:output encoding="iso-8859-1" ...</code> - <strong>OK</strong></li>
<li>input xml file has <code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;</code> - xslt file has <code>&lt;xsl:output encoding="iso-8859-1" ...</code> - <strong>OK</strong></li>
<li>input xml file has <code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;</code> - xslt file has <code>&lt;xsl:output encoding="utf-8" ...</code> - <strong>CORRUPTED</strong> - I see <strong>FÃ¶rstelÃ¤rare</strong> in output xml.</li>
</ol>

<p>input.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
&lt;test&gt;Förstelärare&lt;/test&gt;
</code></pre>

<p>trans.xslt:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" version="1.0" encoding="utf-8" standalone="yes" indent="yes"/&gt;
    &lt;xsl:template match="/"&gt; 
        &lt;xsl:apply-templates select="/test" /&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="test"&gt;
        &lt;test&gt;&lt;xsl:value-of select="text()"/&gt;&lt;/test&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>

<p>C# code:</p>

<pre><code>var xslCompiledTransform = new XslCompiledTransform();
using (var xmlReader = XmlReader.Create(@"C:\trans.xslt", new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, XmlResolver = null }))
{
    xslCompiledTransform.Load(xmlReader);
}
using (var xmlReader = XmlReader.Create(@"C:\input.xml", new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, XmlResolver = null }))
using (var xmlWriter = XmlWriter.Create(@"C:\output.xml", xslCompiledTransform.OutputSettings))
{
    xslCompiledTransform.Transform(xmlReader, xmlWriter);
}
</code></pre>

<p>output.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
&lt;test&gt;FÃ¶rstelÃ¤rare&lt;/test&gt;
</code></pre>

<p>Why does it happen? It looks like I need to use <code>iso-8859-1</code> in my xslt file to prevent corruption cause it works in both cases <code>iso-8859-1</code> and <code>utf-8</code>.</p>