Skip to main content
 首页 » 编程设计

c#之C# 的 XSLT 2.0 版转换问题

2024年02月23日15jackei

您好,我有几个 XSLT 2.0 文件。我需要用 C# 转换这些.. 我使用从该站点获得的以下代码:http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=63

public bool Transform(string XMLPath, string XSLPath, string newXMLname){ 
 
        try{ 
 
            XPathDocument myXMLPath = new XPathDocument(XMLPath);          //load the Xml doc 
            XslCompiledTransform myXSLTrans = new XslCompiledTransform(); 
 
            myXSLTrans.Load(XSLPath);                                       //load the Xsl  
 
            XmlTextWriter myWriter = new XmlTextWriter(newXMLname, null);     //create the output stream 
 
            myXSLTrans.Transform(myXMLPath, null, myWriter);                   //do the actual transform of Xml ---> fout!!?? 
 
            myWriter.Close() ; 
            return true; 
 
 
        }catch(Exception e){ 
 
            return false; 
        } 
    } 

但它不起作用..我认为这是因为我使用 XSLT 2.0 版。 有没有代码/方法可以做到这一点?因为无法将我的 XSLT 文件更改为 1.0 版...

提前致谢!

请您参考如下方法:

设计用于 .NET 环境的两个 XSLT 2.0 处理器是 Saxon.NET 和 XQSharp。

作为 .NET 一部分的 XslCompiledTransform 和 XslTransform 处理器仅实现 XSLT 1.0。