【问题标题】:Transform XML Using XSLT in C#在 C# 中使用 XSLT 转换 XML
【发布时间】:2013-07-09 07:21:24
【问题描述】:

我想使用 xslt 转换 xml 并创建新文件而不是 Visual Studio 中的设置值 xmlcontrol。下面是我的代码。我需要在我的根目录中创建一个名为 tr.xml 的新 XML 转换文件。

  System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(Server.MapPath("hotels.xml"));
            System.Xml.Xsl.XslTransform trans = new
               System.Xml.Xsl.XslTransform();
            trans.Load(Server.MapPath("hotel.xsl"));
            Xml1.Document = doc;
            Xml1.Transform = trans;

有人可以帮忙吗?/

【问题讨论】:

标签: c# asp.net xml xslt


【解决方案1】:

如果您想在 .NET 2.0 及更高版本中使用 XSLT 1.0 将输入文件转换为输出文件,那么您应该使用 XslCompiledTransform,这很简单

XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(Server.MapPath("hotels.xsl"));

proc.Transform(Server.MapPath("hotels.xml"), Server.MapPath("tr.xml"));

有关XslCompiledTransform 及其可能的输入和输出的详细文档,请参阅http://msdn.microsoft.com/en-us/library/0610k0w4.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多