以下代码可以工作,但是很混乱而且速度慢。 我正在使用Saxon的XSLT2将XDocument转换为另一个XDocument,并使用SaxonWrapper进行适应:
public static XDocument HSRTransform(XDocument source)
{
System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream xslfile = thisExe.GetManifestResourceStream("C2KDataTransform.Resources.hsr.xsl");
XmlDocument xslDoc = new XmlDocument();
xslDoc.Load(xslfile);
XmlDocument sourceDoc = new XmlDocument();
sourceDoc.Load(source.CreateReader());
var sw = new StringWriter();
Xsl2Processor processor = new Xsl2Processor();
processor.Load(xslDoc);
processor.Transform(sourceDoc, new XmlTextWriter(sw));
XDocument outputDoc = XDocument.Parse(sw.ToString());
return outputDoc;
}
我意识到速度慢可能实际上是在我无法控制的部分,但是是否有更好的方法来处理XDocument和XmlDocument之间的所有切换以及写入器的使用?