XPathDocument myXPathDoc = new XPathDocument(<xml file path>) ;
XslTransform myXslTrans = new XslTransform() ; myXslTrans.Load(<xsl file path>);
XmlTextWriter myWriter = new XmlTextWriter("result.html",null) ;
myXslTrans.Transform(myXPathDoc,null,myWriter) ;
XmlTransformUtil.exe <xml file path> <xsl file path>
using System ; using System.IO ; using System.Xml ; using System.Xml.Xsl ; using System.Xml.XPath ; public class XmlTransformUtil{ public static void Main(string[] args){ if (args.Length == 2){ Transform(args[0], args[1]) ; }else{ PrintUsage() ; } } public static void Transform(string sXmlPath, string sXslPath){ try{ //load the Xml doc XPathDocument myXPathDoc = new XPathDocument(sXmlPath) ; XslTransform myXslTrans = new XslTransform() ; //load the Xsl myXslTrans.Load(sXslPath) ; //create the output stream XmlTextWriter myWriter = new XmlTextWriter ("result.html", null); //do the actual transform of Xml myXslTrans.Transform(myXPathDoc,null, myWriter); myWriter.Close() ; }catch(Exception e){ Console.WriteLine("Exception: {0}", e.ToString()); } } public static void PrintUsage(){ Console.WriteLine ("Usage: XmlTransformUtil.exe <xml path> <xsl path>"); } }
Build Your Own ASP.NET Website Using C# & VB.NET