Rendering XML formated as HTML using XSLT

Source XML with HTML formatted text inside

<Wizard.com_filing version="2.1">
βˆ’
<FILING_INFO>
<NAME>DEREK REYNOLDS CO</NAME>
<FILER>DEREK REYNOLDS CO</FILER>
<DATE_FILED>20070731</DATE_FILED>
<FORM>15-12G</FORM>
<SIZE>17.1 KB</SIZE>
<PAGES>1</PAGES>
</FILING_INFO>
βˆ’
<FILING view="Entire">
βˆ’
<DOCUMENT type="HTML" number="1">
<html>
  
  <head>
    <title>tncform15.htm</title>
</head>
  <body bgcolor="#ffffff"><br>
    <div style="DISPLAY: block; MARGIN-LEFT: 0pt; TEXT-INDENT: 0pt; MARGIN-RIGHT: 0pt" align="center"><font style="DISPLAY: inline; FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman;"><strong>UNITED
      STATES</strong></font></div>
    <div style="DISPLAY: block; MARGIN-LEFT: 0pt; TEXT-INDENT: 0pt; MARGIN-RIGHT: 0pt" align="center"><font style="DISPLAY: inline; FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman;"><strong>SECURITIES
      AND EXCHANGE COMMISSION</strong></font></div>
    <div style="DISPLAY: block; MARGIN-LEFT: 0pt; TEXT-INDENT: 0pt; MARGIN-RIGHT: 0pt" align="center"><font style="DISPLAY: inline; FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman;"><strong>WASHINGTON,
      D.C. 20549</strong></font></div>
    <div><br></div>
    <div style="DISPLAY: block; MARGIN-LEFT: 0pt; TEXT-INDENT: 0pt; MARGIN-RIGHT: 0pt" align="justify"> </div>
    <div style="DISPLAY: block; MARGIN-LEFT: 0pt; TEXT-INDENT: 0pt; MARGIN-RIGHT: 0pt" align="center"><font style="DISPLAY: inline; FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman;"><strong>FORM
      15</strong></font></div>
    <div><br></div>
    <div style="DISPLAY: block; MARGIN-LEFT: 0pt; TEXT-INDENT: 0pt; MARGIN-RIGHT: 0pt" align="justify"><font style="DISPLAY: inline; FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman;">CERTIFICATION
      AND NOTICE OF TERMINATION OF REGISTRATION UNDER SECTION 12(g) OF THE SECURITIES
      EXCHANGE ACT OF 1934 OR SUSPENSION OF DUTY TO FILE REPORTS UNDER SECTIONS 13
      AND 
      15(d) OF THE SECURITIES EXCHANGE ACT OF 1934.</font></div>
...
..
.

XSLT filtering out only the DOCUMENT portion containing the HTML (HTMLView.xslt)
Note: disable-output-escaping=”yes” is required, otherwise the HTML markup will not be rendered in browser. If you exclude this the output will just be the HTML source.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:value-of select="/Wizard.com_filing/FILING/DOCUMENT"  disable-output-escaping="yes"/>
  </xsl:template>
</xsl:stylesheet>

ASP.NET code to transform XML using XSLT



<script runat="server">
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        string xmlUrl = "http://ccbn.10kwizard.com/xml/filing.xml?repo=tenk&ipage=5076639&attach=ON&sXBRL=1";
       

        xmlOutput.DocumentContent = RetrieveXML(xmlUrl);

        xmlOutput.TransformSource = Server.MapPath("HTMLView.xslt");


       

    }

   

    private static string RetrieveXML(string url)
    {
        // Create the WebRequest for the URL we are using
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
        req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";

        // Get the stream from the returned web response
        StreamReader stream = new StreamReader(req.GetResponse().GetResponseStream());

        //experiment try reading entire thing at once
        string html = stream.ReadToEnd();

        // Finished with the stream so close it now
        stream.Close();

        return html;

    }

    
    


</script>

<html>
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Xml ID="xmlOutput" runat="server" Visible="true"></asp:Xml>      
    </div>
    </form>
</body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s