locked
Convert From XMl String to HMTL using XSLT RRS feed

  • Question

  • User-1399352090 posted

    Hi,

    I'm trying to covert xml data to html to but i'm getting  html string with black slashes. 

    like : 

    <table width=\"806\" border=\"0\" 
    align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\r\n
    <tr>\r\n <td height=\"55\"> </td>\r\n </tr>\r\n
    <tr>\r\n <td style=\"padding-bottom:15px;\">\r\n
    <img src=\"http://www.mystie.com/images/aeb8e2d5.png\" alt=\"site\" border=\"0\" />\r\n
    </td>\r\n </tr>\r\n <tr>\r\n
    <td height=\"30\"> </td>\r\n </tr>\r\n <tr>\r\n
    <td style=\"font-family: Arial, sans-serif, Verdana; color:#231f20;font-size:24px;font-weight:notmal;\">\r\n
    <strong>HELLO!</strong> YOU'VE JUST RECEIVED A DAR YAZ GIFT CARD.</td>\r\n </tr>\r\n <tr></table>

    how to get normal html string with out appending \ and \r\n

    here my code:

    public static string GiftOrder(int gOrderID)
            {
    
                string strXSLT = string.Empty;
                strXSLT = GetHtml(CommonLogic.SafeMapPath("~/EmailTemplates/Userpurchased_GiftCard.xsl"), GetGiftOrderXML(gOrderID));
                return strXSLT.ToString();
            }
     private static string GetGiftOrderXML(int gOrderID)
            {
                string strXML = string.Empty;
                GiftCardOrder gOrder = new GiftCardOrder(gOrderID);
                StringWriter sw = new StringWriter();
                XmlSerializer s = new XmlSerializer(typeof(GiftCardOrder));
                s.Serialize(sw, gOrder);
                strXML = sw.ToString().Replace("\r\n", "");
                return strXML;
            }
    
     private static string GetHtml(string xsltPath, string xml)
            {
                string encoding = "UTF-16";
                MemoryStream stream = new MemoryStream(Encoding.GetEncoding(encoding).GetBytes(xml));
                XPathDocument document = new XPathDocument(stream);
                StringWriter writer = new StringWriter();
                XslCompiledTransform transform = new XslCompiledTransform();
                XsltSettings xslSet = new XsltSettings();
                xslSet.EnableScript = true;
                transform.Load(xsltPath, xslSet, new XmlUrlResolver());
                
                transform.Transform(document, null, writer);
                return writer.ToString();
            }
    //to get string for html
    
    string htmlstring= GiftOrder(3333);
    
    

    Appreciate for Quick and best response.

    Tuesday, December 29, 2015 4:18 PM

Answers

All replies