c# - Apply XSLT on in-memory XML and returning in-memory XML -


I'm looking for a static job in the .NET framework that changes an XML snippet and an XSLT file Applies memory, and converted XML

I would like to do this:

  string rawxml = invoiceTemplateDoc.MainDocumentPart.Document.InnerXml; RawXml = DoXsltTransformation (rawXml, @ "c: \ ready-invoice.xslt")); // ... more manipulations on rawXml  

Alternatively, instead of taking the string and returning, it can move XmlNodes and return.

Is such a function?

A little bit is that you can actually copy the data directly to XmlDocument DOM Or without passing through a LINQ-to-XML XElement or XDocument (via the CreateWriter () method)

Assume that your XML input is IXPathNavigable and you have loaded a XslCompiledTransform for example, you can do the following:

  XmlDocument target = new XML document (input.CreateNavigator (.net) NameTable); (XMLR Writer Writer = Target. Crenant Navigator (). Ependibil ()) {Transform. Transform (input, author); }  

Then you have the converted document in the taget document. Note that you have to allow XSLT arguments and the extension to pass in the stylesheet. There are other surcharges on the code> Change .

If you want you to write your own stable helper or extension method, make changes according to your requirement. However, it can be a good idea to cache after shipment and compilation that it is not free.


Comments