小编典典

如何在C#中应用XSLT样式表

c#

我想使用C#将XSLT样式表应用于XML文档,并将输出写入文件。


阅读 228

收藏
2020-05-19

共1个答案

小编典典

我在这里找到了可能的答案: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) ;

编辑:

但是我可信赖的编译器说过时了XslTransformXslCompiledTransform改用:

XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ;
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(myStyleSheet);
XmlTextWriter myWriter = new XmlTextWriter("result.html",null);
myXslTrans.Transform(myXPathDoc,null,myWriter);
2020-05-19