Reputation: 5622
I'm trying to switch from XSLTCompiledTransformation to Saxon XSLTTransformation but I have problems with specifying output destination as XML document to saxon xslt transformation.
This is the old code used for executing xslt transformations:
XsltCompiledTransform transform = ... load xslt transform
XsltArgumentList arguments = ... load arguments
var result = new XmlDocument();
using(var xmlReader = new XmlNodeReader(inputXml)) {
using(var writer = result.CreateNavigator().AppendChild())
transform.Transform(xmlReader, arguments, writer);
}
I've tried to rewrite this to use Saxon library but I have problem with output xmlDocument:
XsltTransformer transform = ... load xslt transform
var result = new XmlDocument();
Processor processor = new Processor()
XdmNode input = pro.NewDocumentBuilder().Wrap(inputXml);
transform.InitialContextNode = input;
//tried specifying result as XMLDestination:
transform.Run(result); //getting error
//also tried this:
using(var writer = result.CreateNavigator().AppendChild())
transform.Run(writer);
How can I convert XMLDocument to XmlDestination or how can I setup destination and then convert that result back to XMLDocument?
Upvotes: 2
Views: 335
Reputation: 167401
Use a DOMDestination
http://saxonica.com/html/documentation9.6/dotnetdoc/Saxon/Api/DomDestination.html#DomDestination%28%29, e.g.
var result = new DOMDestination();
transform.Run(result);
var resultDoc = result.XmlDocument; // now resultDoc is an XmlDocument
Or as an alternative
var result = new XmlDocument();
transform.Run(new DOMDestination(result));
Upvotes: 2