我想使用C#将XSLT样式表应用于XML文档,并将输出写入文件。
我在这里找到了可能的答案:http : //web.archive.org/web/20130329123237/http : //www.csharpfriends.com/Articles/getArticle.aspx?articleID=63
从文章:
XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ; XslTransform myXslTrans = new XslTransform() ; myXslTrans.Load(myStyleSheet); XmlTextWriter myWriter = new XmlTextWriter("result.html",null) ; myXslTrans.Transform(myXPathDoc,null,myWriter) ;
编辑:
但是我可信赖的编译器说过时了XslTransform:XslCompiledTransform改用:
XslTransform
XslCompiledTransform
XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ; XslCompiledTransform myXslTrans = new XslCompiledTransform(); myXslTrans.Load(myStyleSheet); XmlTextWriter myWriter = new XmlTextWriter("result.html",null); myXslTrans.Transform(myXPathDoc,null,myWriter);