DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4375>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4375 Using a StringReader in the InputSource of stylesheet causes incorrect character encoding Summary: Using a StringReader in the InputSource of stylesheet causes incorrect character encoding Product: XalanJ2 Version: 2.2.x Platform: All OS/Version: All Status: NEW Severity: Normal Priority: Other Component: Xalan AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] In my trasformation class, I receive xsl markup as a Java String. Xalan doesn't take into account that the Java-String is always encoded in UniCode and not by the encoding in the xml declaration. Note: This issue does not occur when using a StringReader for the xml source. ---------- Test Case: ---------- FileReader fReader = new FileReader("foo.xsl"); StringWriter sWriter = new StringWriter(); int c; while ((c=fReader.read()) != -1) { sWriter.write(c); } TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer (new javax.xml.transform.stream.StreamSource (new StringReader(sWriter.toString()))); transformer.transform(new StreamSource("foo.xml"), new StreamResult(new FileOutputStream("foo.out"))); -------- foo.xml: -------- <?xml version="1.0" encoding="UTF-8"?> <root> <child1> <xsl-copy>foo</xsl-copy> </child1> <child2> <copy>�</copy> </child2> <child3>bar</child3> </root> -------- foo.xsl: -------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="node()"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="xsl-copy"> <xsl:copy>�</xsl:copy> </xsl:template> </xsl:stylesheet> ---------------- expected output: ---------------- <?xml version="1.0" encoding="UTF-8"?> <root> <child1> <xsl-copy>@</xsl-copy> </child1> <child2> <copy>�</copy> </child2> <child3>bar</child3> </root> -------------- actual output: -------------- <?xml version="1.0" encoding="UTF-8"?> <root> <child1> <xsl-copy>©</xsl-copy> </child1> <child2> <copy>�</copy> </child2> <child3>bar</child3> </root>
