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