Monday, 27 May 2013

Preserve whitespace in BizTalk Transform

Preserving Whitespaces in BizTalk Transformation

Following property need to be set            r_setting.IgnoreWhitespace = false;
Full Sample code

          XsltSettings set = new XsltSettings(true, true);
        XmlReader reader;
        XmlWriter writer;
        string xmlPath_out = "D:/" + "testWhiteSpace.xml";
        //StreamWriter writer = File.CreateText(xmlPath_out);
            string xml_p = "testWhite_P.xml";
            string xslt_p = "xsltWhiteSpace.xsl";
            string xmlPath = Server.MapPath(xml_p);
            string xslPath = Server.MapPath(xslt_p);

            //Instantiate the XslTransform Class
            XslCompiledTransform transform = new XslCompiledTransform();
            XmlResolver secureResolver = new XmlSecureResolver(new XmlUrlResolver(), xmlPath);
            XmlReaderSettings r_setting = new XmlReaderSettings();

            transform.Load(xslPath, set, secureResolver);
            r_setting.IgnoreWhitespace = false;

            reader = XmlReader.Create(xmlPath, r_setting);
            XmlWriterSettings w_setting = new XmlWriterSettings();
            writer = XmlWriter.Create(xmlPath_out, w_setting);
            transform.Transform(reader, null, writer);



Node that need  to be added in custom XSLT file
<xsl:preserve-space elements="*"/>  Please refer section 3.4 for link