Rositsa Ruseva

Rositsa Ruseva

  • 2.1k
  • 84
  • 3.4k

XSLT Tranform XSLT file to XML with C#

May 17 2022 1:23 PM
AppContext.SetSwitch("Switch.System.Xml.AllowDefaultResolver", true);
var xsltransf = new XslCompiledTransform();
var xmlMemoryDoc = new XmlDocument();
xmlMemoryDoc.Load(new StringReader(XElement.Load(@"D:\PRJ\SPM.861\SEE PM - WEB SERVICE\3.08.1.5\Default\Env\ContentVisualisations\WD\Diagram_Content_HTML_WD_View_HierarchicalCables (1).XSLT").ToString()));
var xmlFileDoc = new XmlDocument();
xmlFileDoc.Load(@"D:\PRJ\SPM.861\SEE PM - WEB SERVICE\3.08.1.5\Default\Env\ContentVisualisations\WD\Diagram_Content_HTML_WD_View_HierarchicalCables (1).XSLT");
xsltransf.Load(xmlFileDoc, new XsltSettings { EnableDocumentFunction = true }, new XmlUrlResolver());
var contentXPathDoc = new XPathDocument(XmlReader.Create(new StringReader(XElement.Load(@"D:\PRJ\SPM.861\SEE PM - WEB SERVICE\3.08.1.5\Default\Env\ContentVisualisations\WD\WD.xml").ToString())));
var writer = new StringWriter();
// File.WriteAllText(@"D:\PRJ\SPM.861\result.html", writer.ToString());
xsltransf.Transform(contentXPathDoc.CreateNavigator(), null, writer/*, @"D:\Prj\SPM\8.50\1\SEE PM - WEB SERVICE\3.07.1.7\Default\Env\ContentVisualisations\WD\out.html"*/);
var sr = writer.ToString();

I have this code and I have to add in a specific place in the xslt file "document" (as in the image). We have an XSLT file that is transformed to XML file but in the original file the element "document" is missing. Any idea how to add it?