White space cannot be stripped from input documents that have already been loaded. Provide the input document as an XmlReader instead

后端 未结 1 1140
既然无缘
既然无缘 2021-01-21 03:44

I want to transform a XML document, but having a problem.

My XSLT looks like this:

 


        
相关标签:
1条回答
  • 2021-01-21 04:34

    I solved it. Actually "XslCompiledTransform.Transform" takes XmlReader as first Parameter and i was passing XmlDocument in First Paramenter. Here is the code.

    public static string Transform(XmlDocument doc, XmlDocument stylesheet)
        {
            try
            {
                System.Xml.Xsl.XslCompiledTransform transform = new System.Xml.Xsl.XslCompiledTransform();
                transform.Load(stylesheet); // compiled stylesheet
                System.IO.StringWriter writer = new System.IO.StringWriter();
                XmlReader xmlReadB = new XmlTextReader(new StringReader(doc.DocumentElement.OuterXml));
                transform.Transform(xmlReadB, null, writer);
                return writer.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
    
        }
    
    0 讨论(0)
提交回复
热议问题