I am currently running a live 'in-memory' XSLT transformation using the following code

XmlDocument XmlDoc = new XmlDocument();

            XslCompiledTransform XsltTranformation = new XslCompiledTransform();

            Stream XmlStream = new MemoryStream();
            XmlDoc.Save(XmlStream); //Stream is still blank after this line
            XmlReader XmlRdr = XmlReader.Create(XmlStream);

            MemoryStream stm = new MemoryStream();
            XsltTranformation.Transform(XmlRdr, null, stm);
            stm.Position = 1;

            StreamReader sr = new StreamReader(stm);
            string Output = sr.ReadToEnd();
            Output = Output.Substring(2);

            XmlWriter XmlWrtr = XmlWriter.Create(@"C:\Users\maskew\Desktop\XmlMapping.xml");

However, when I move the file from XmlDocument to MemoryStream in line 8 the stream contains nothing when checked and thus stopping the whole program from running.

Does anyone have any idea why this would be occuring?


            XDocument XmlDoc = XDocument.Parse(DS.GetXml());

            // Create a writer for writing the transformed file.
            XmlWriter writer = XmlWriter.Create(@"C:\Users\maskew\Desktop\XmlMapping.xml");

            // Create and load the transform with script execution enabled.
            XslCompiledTransform XSLTTransformer = new XslCompiledTransform();
            XsltSettings settings = new XsltSettings();
            settings.EnableScript = true;
            XSLTTransformer.Load(@"C:\Users\maskew\Desktop\XSLTMapping.xsl", settings, null);

            // Execute the transformation.
            XSLTTransformer.Transform(XmlDoc.CreateReader(), writer);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.