我想使用 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);