You must Sign In to post a response.
  • Category: XML

    How can we convert the xml page in to html page

    how can we convert the xml page in to html page..........................
  • #647183
    You can achive it with the help of xslt.

    Please check the sample code:

    Sample.xml
    ----------


    <?xml version="1.0" encoding="UTF-8" ?>
    <?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
    <bookstore>
    <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
    </book>
    <book category="children">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
    </book>
    </bookstore>


    Sample.xsl
    ----------


    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Untitled Document</title>
    </head>

    <body>
    <h1> catalogues of books</h1>
    <table border="1" cellpadding="2px">
    <tr bgcolor="#3399FF">
    <th>TITLE</th>
    <th>CATEGORY</th>
    <th>LANGUAGE</th>
    <th>AUTHOR</th>
    <th>YEAR</th>
    <th>PRICE</th>
    </tr>
    <xsl:for-each select="bookstore/book">
    <tr>

    <td>
    <xsl:value-of select="title" />
    </td>
    <td>
    <xsl:value-of select="@category" />
    </td>
    <td>
    <xsl:value-of select="title/@lang" />
    </td>
    <td>
    <xsl:value-of select="author" />
    </td>
    <td>
    <xsl:value-of select="year" />
    </td>
    <td>
    <xsl:value-of select="price" />
    </td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>


    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #648153
    Hi
    The solution for this is to use an XSLT stylesheet to transform the XML into another format using the XslTransform class. In the example code, we are transforming some personnel data from a fictitious business stored in Personnel.xml. First, we load the stylesheet for generating HTML output. Then we perform the transformation to HTML via XSLT using the PersonnelHTML.xsl stylesheet. After that, we transform the data to comma-delimited format using the PersonnelCSV.xsl stylesheet

    Regards
    Kamlesh Mohanty

  • #648156
    Hi,

    Please check below code:


    using System;
    using System.Xml;
    using System.IO;
    using System.Xml.XPath;
    using System.Xml.Xsl;



    public class XTH
    {

    static void Main(string[] args)
    {
    XslTransform xt = new XslTransform();
    xt.Load("Test.xsl");
    XPathDocument xDoc = new XPathDocument("Test.xml");
    XmlTextWriter writer = new XmlTextWriter("Test.html", null);
    xt.Transform(xDoc, null, writer, new XmlUrlResolver());
    writer.Close();
    StreamReader stream = new StreamReader("Test.html");
    Console.Write(stream.ReadToEnd());
    }
    }


    Regards
    Rajesh

    Regards
    Mr.Rajesh
    Software Engg.

  • #648814
    Hi!
    >>The solution for this is to use an XSLT stylesheet to transform the XML into another format using the XslTransform class.

    public static void TransformXML( )
    {
    XmlUrlResolver resolver = new XmlUrlResolver( );
    resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
    XslTransform transform = new XslTransform( );
    transform.Load(@"..\PersonnelHTML.xsl",resolver);
    transform.Transform(@"..\Personnel.xml",@"..\Personnel.html",resolver);
    transform.Load(@"..\PersonnelCSV.xsl",resolver);
    transform.Transform(@"..\Personnel.xml", @"..\Personnel.csv",resolver);
    }

    Regards
    Kamlesh

    Regards
    Kamlesh Mohanty


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.