View Full Version : Convert XslTransform to XslCompiledTransform

11-14-2011, 05:11 PM
Hi - I just converted an ASP.Net web app from 2.0 to 4.0 and the XslTransform code that I inherited no longer works in 4.0. I'm told I need to change the code to use XslCompiledTransform. Fine - but I can't figure out how to get XslCompiledTransform to do exactly what I need it to do. I have an XSL file in my project. I do not have an XML or HTML file. The old code read as follows:

using (DataSet data = DataGateway.getAbsence(TripNum))
data.DataSetName = "Absence";
data.Tables[0].TableName = "Employee";
XmlDataDocument xmldoc = new XmlDataDocument(Data);
XslTransform xslt = new XslTransform;
string xsltfile = "myfile.xsl";
TextWriter writer = new StringWriter();
xslt.Transform(xmldoc, null, writer, null);
MailMessage mail = new MailMessage();
mail.Body = writer.ToString();
mail.From = "me";
mail.To = "you";
//more code to send mail......
I've tried to rewrite this by substituting and XsltCompiledTransform object for the XslTransform object, and an XmlWriter object for the TextWriter object, but the xslt.Transform line complains about my using an XmlDataDocument as input. It suggests an XmlReader instead, but I don't know how to pass the data from my DataSet into an XmlReader. Or perhaps XslCompiledTransform is not the way to go Does anyone know?


11-16-2011, 08:46 PM
I got a response to this issue from Javeed M Shaikh on C-SharpCorner.com (big shout out to Javeed). This works beautifully converting a Dataset to XML:

XmlTextReader mXmlTextReader = new XmlTextReader(data.GetXml(),XmlNodeType.Document, null);

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum