如何在 C# 中应用 XSLT 样式表 [英] How to apply an XSLT Stylesheet in C#
本文介绍了如何在 C# 中应用 XSLT 样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 C# 将 XSLT 样式表应用于 XML 文档并将输出写入文件.
I want to apply an XSLT Stylesheet to an XML Document using C# and write the output to a File.
推荐答案
我在这里找到了一个可能的答案:http://web.archive.org/web/20130329123237/http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=63
I found a possible answer here: 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
代替:
But my trusty compiler says, XslTransform
is obsolete: Use XslCompiledTransform
instead:
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# 中应用 XSLT 样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文