// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.IO; using System.Xml; using System.Xml.Xsl; namespace XmlProc.XSLT { public class Program { private const string XML_FILE = @"C:\work\employees.xml"; private const string XSL_FILE = @"C:\work\employees.xsl"; public static void Main(string[] args) { // read from file to DOM tree XmlDocument doc = new XmlDocument(); doc.Load(XML_FILE); // transform from DOM to another file XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load(XSL_FILE); using(StreamWriter sw = new StreamWriter(@"C:\work\employees2.xml")) { XmlWriterSettings xws = new XmlWriterSettings(); xws.Indent = true; XmlWriter xw = XmlWriter.Create(sw, xws); xslt.Transform(doc, xw); } } } }