Tuesday, October 16, 2007

How to Transform A DataSet using Xml and Xslt in .Net 2.0

// Creating DOM Document
XmlDocument doc = new XmlDocument();

// Get hold of the XML string from the dataset
doc.LoadXml(ds.GetXml());

//Load XSL and Tranform
XslCompiledTransform myXslTrans = new XslCompiledTransform();
string path = Directory.GetCurrentDirectory();
myXslTrans.Load(path + @"\PrintView.xslt");

// Using a StringWriter for Streaming part
StringWriter stringWriter = new StringWriter();

// The actual transformation
myXslTrans.Transform(doc.DocumentElement, null, stringWriter);
stringWriter.Flush();

// Consuming the transformed results
webBrowser1.Document.Write(stringWriter.ToString());

//doc.Save("Example.xml");

No comments: