I am transforming my XML file to another XML file using the XslCompiledTransform classes available in the .NET framework 3.5
Here's my code.
private static void transformUtil(string sXmlPath, string sXslPath, string outputFileName)
{
try
{
XPathDocument myXPathDoc = new XPathDocument(sXmlPath);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
//load the Xsl
myXslTrans.Load(sXslPath);
//create the output stream
XmlTextWriter myWriter = new XmlTextWriter(outputFileName, null);
//do the actual transform of Xml
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();
}
catch (Exception e)
{
EventLogger eventLog;
eventLog = new EventLogger("transformUtil", e.ToString());
}
}
}
The code works, but the output file does not have the XML declaration in the header.
**<?xml version="1.0" encoding="utf-8"?>**
I am at a loss to understand this. When I use the same XSL file to transform the XML, using a tool like notepad++ or visual studio, the transformation contains the XML declaration in the header. So is XslCompiledTransform responsible for truncating this declaration? I am puzzled.
Anyone else facing similar issues?
My XSL file header looks like this.
<?xml version="1.0" encoding="iso-8859-1"?>