Microsoft XSLT supports XSLT 1.0 standard only.
Unfortunately, SSIS XML Task, operation XSLT transformation always emits BOM.
A solution for that is to use SSIS Script Task for XSLT Transformations.
Here is how to do it. As a bonus, it even shows how to pass parameters to the XSLT.
c#
void Main()
{
const string SOURCEXMLFILE = @"e:\Temp\UniversalShipment.xml";
const string XSLTFILE = @"e:\Temp\UniversalShipment.xslt";
const string OUTPUTXMLFILE = @"e:\temp\UniversalShipment_output.xml";
bool paramXSLT = true;
try
{
XsltArgumentList xslArg = new XsltArgumentList();
if (paramXSLT)
{
// Create a parameter which represents the current date and time.
DateTime d = DateTime.Now;
xslArg.AddParam("date", "", d.ToString());
}
using (XmlReader src = XmlReader.Create(SOURCEXMLFILE))
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XSLTFILE, new XsltSettings(true, true), new XmlUrlResolver());
XmlWriterSettings settings = xslt.OutputSettings.Clone();
settings.IndentChars = "\t";
// to remove BOM
settings.Encoding = new UTF8Encoding(false);
using (XmlWriter result = XmlWriter.Create(OUTPUTXMLFILE, settings))
{
xslt.Transform(src, xslArg, result, new XmlUrlResolver());
result.Close();
}
}
Console.WriteLine("File '{0}' has been generated.", OUTPUTXMLFILE);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}