//加载xsl样式表文件
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("path/to/your/xsl/file.xsl");
// 加载XML文件
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("path/to/your/xml/file.xml");
// 创建一个StringWriter来保存转换后的结果
StringWriter stringWriter = new StringWriter();
// 创建一个XmlTextWriter,将其绑定到StringWriter
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
// 也可以根据需要将转化内容输出到文件中,保存转换后的结果
//XmlTextWriter writer = new XmlTextWriter("path/to/save/transformed/xml.xml", null);
// 执行转换
xslt.Transform(xmlDoc, null, xmlWriter);
// 获取转换结果的字符串
string transformedXml = stringWriter.ToString();
// 关闭writers和其他资源
xmlWriter.Close();
stringWriter.Close();
// 打印转换结果的字符串
Console.WriteLine(transformedXml);
标签:XML,xml,C#,XmlTextWriter,stringWriter,StringWriter,new,XSL
From: https://www.cnblogs.com/Mxy-cnblog/p/17676033.html