调用xlst执行转换

Posted on 2023-07-13 10:21  云起  阅读(15)  评论(0编辑  收藏  举报  来源
try
{
    //Create a new XslTransform object.
    XslCompiledTransform xslt = new XslCompiledTransform();
    //Load the stylesheet.
    var xlst = "xlstPath";
    xslt.Load(xlst);
    //Create a new XPathDocument and load the XML data to be transformed.
    var path = "xmlPath";
    XPathDocument mydata = new XPathDocument(path);
    //Create an XmlTextWriter which outputs to the console.
    XmlWriter writer = new XmlTextWriter(Console.Out);
    //Transform the data and send the output to the console.
    xslt.Transform(mydata, null, writer, null);
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
    Console.WriteLine(ex.InnerException.Message);
}

参考:https://learn.microsoft.com/zh-cn/dotnet/standard/data/xml/how-to-perform-an-xslt-transformation-by-using-an-assembly

Copyright © 2024 云起
Powered by .NET 9.0 on Kubernetes