XSL: Special Characters being rendered for whitespace after Transformation is applied in .NET

While using .NET 1.1 for XSL Transforms, I was running into funky special
characters ": Pump Go " which were sprinkled wherever I had intentionally added white space in the xsl stylesheet file.
Google didn't throw up anything on this... Could I be the first man to step here. No - couldn't be...
Here's the snippet I used

XmlResolver obResolver=new XmlUrlResolver();
XPathDocument obFasterPerfDoc=
new XPathDocument(sDataStorePath);
XslTransform obTransformer=
new XslTransform();
using (FileStream fs=new FileStream(sReportPath, FileMode.Create, FileAccess.Write, FileShare.None)){
using (TextWriter tw=new StreamWriter(fs)){
null, tw, obResolver);

I struggled with it for a bit then let it be.. But now I seem to have run into the
solution. Use XMLTextWriter instead of TextWriter. XMLTextWriter doesn't implement
IDisposable. So can't use "using" blocks but the special character issue has gone away now.
So here's the modded code

*snip using
(FileStream fs=new FileStream(sReportPath, FileMode.Create, FileAccess.Write, FileShare.None)){
XmlTextWriter xtw=
new XmlTextWriter(fs, System.Text.Encoding.Unicode);
try {
XslTransform obTransformer=
new XslTransform();
obTransformer.Transform(obFasterPerfDoc, null, xtw, obResolver);
finally {

No comments:

Post a Comment