我想使用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:
XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ;
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(myStyleSheet);
XmlTextWriter myWriter = new XmlTextWriter("result.html",null);
myXslTrans.Transform(myXPathDoc,null,myWriter);

关于c# - 如何在C#中应用XSLT样式表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34093/

10-11 23:27