[Mono-bugs] [Bug 52913][Nor] New - XslTransform.Transform - incorrect encoding when outputting to a FileStream

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 15 Jan 2004 15:54:12 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by dol@2a.pl.

http://bugzilla.ximian.com/show_bug.cgi?id=52913

--- shadow/52913	2004-01-15 15:54:12.000000000 -0500
+++ shadow/52913.tmp.1179	2004-01-15 15:54:12.000000000 -0500
@@ -0,0 +1,122 @@
+Bug#: 52913
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.XML
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: dol@2a.pl               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: XslTransform.Transform - incorrect encoding when outputting to a FileStream
+
+Description
+-----------
+
+When 'Transform(XPathNavigator input, XsltArgumentList args, Stream output)'
+overload of the 'System.Xml.Xsl.XslTransform' class is used,
+the 'encoding' attribute of the 'xsl:output' directive is ignored.
+
+Some other overloads of this method - 
+'Transform (string inputfile, string outputfile)'
+in particular - are not affected.
+
+
+Steps to reproduce
+------------------
+
+The following code fragment exhibits this problem.
+
+==== test-xslt-encoding.cs
+using System.IO;
+using System.Xml;
+using System.Xml.Xsl;
+
+class TestXsltEncoding
+{
+  public static void Main()
+  {
+    XmlDocument xd = new XmlDocument();
+    XslTransform xslt = new XslTransform();
+    Stream fs;
+
+    xslt.Load("test.xsl");
+
+    // Use simple Transform - result is OK
+    xslt.Transform("test.xml", "out-simple.xml");
+
+    // Use FileStream - uses UTF-8
+    xd.Load("test.xml");
+    fs = new FileStream("out-fs.xml", FileMode.Create);
+    xslt.Transform(xd, null, fs);
+    fs.Close();
+  }
+}
+====
+
+==== test.xsl
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:output encoding="ISO-8859-2" />
+
+  <xsl:template match="/">
+    <output><xsl:apply-templates /></output>
+  </xsl:template>
+
+</xsl:stylesheet>
+====
+
+==== test.xml (
+<?xml version="1.0"?>
+<test>&#261;</test>
+====
+
+
+Actual Results
+--------------
+
+'out-simple.xml' uses encoding specified in test.xsl,
+'out-fs.xml' is encoded in UTF-8.
+
+
+Expected Results
+----------------
+
+Both files 'out-simple.xml' and 'out-fs.xml' should use
+the same encoding specified in test.xsl. 
+
+
+How often does this happen?
+---------------------------
+
+Always
+
+
+Additional Information
+----------------------
+
+The following patch seems to correct this problem (at least for the
+managed XSLT implementation).
+
+Index: Multiplexer.cs
+===================================================================
+RCS file: /mono/mcs/class/System.XML/System.Xml.Xsl/Multiplexer.cs,v
+retrieving revision 1.6
+diff -r1.6 Multiplexer.cs
+153c153
+< 			impl.Transform (input, args, new XmlTextWriter (output, null),
+xmlResolver);
+---
+> 			impl.Transform (input, args, output, xmlResolver);
+
+161c161
+< 			impl.Transform (input, args, new XmlTextWriter (output, null), resolver);
+---
+> 			impl.Transform (input, args, output, resolver);