title: how to execute and display xslt result on webpage?
body: <p>I have the following three files and what it should do is taking the xml and xsl files and process them according and display the result in the browser. But now the problem is when I double click the html by chrome and IE7, I all got blank page. Can anyone tell why it's like this and what's the right way to execute a xslt file and display the result on a webpage? Thanks a lot.</p>
  
  <pre><code>student.xml file
  
  &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  
  &lt;data&gt;
   &lt;student&gt;
    &lt;name&gt;Bitu Kumar&lt;/name&gt;
    &lt;course&gt;MCA&lt;/course&gt;
    &lt;sem&gt;6&lt;/sem&gt;
    &lt;marks&gt;80&lt;/marks&gt;
   &lt;/student&gt;
   &lt;student&gt;
    &lt;name&gt;Santosh Kumar&lt;/name&gt;
    &lt;course&gt;MCA&lt;/course&gt;
    &lt;sem&gt;5&lt;/sem&gt;
    &lt;marks&gt;70&lt;/marks&gt;
   &lt;/student&gt;
   &lt;student&gt;
    &lt;name&gt;Ashish&lt;/name&gt;
    &lt;course&gt;M.Sc.&lt;/course&gt;
    &lt;sem&gt;4&lt;/sem&gt;
    &lt;marks&gt;80&lt;/marks&gt;
   &lt;/student&gt;
   &lt;student&gt;
    &lt;name&gt;Mahesh&lt;/name&gt;
    &lt;course&gt;MA&lt;/course&gt;
    &lt;sem&gt;3&lt;/sem&gt;
    &lt;marks&gt;80&lt;/marks&gt;
   &lt;/student&gt;
  &lt;/data&gt;
  
  and following student.xsl file
  
  &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:template match="/"&gt;
   &lt;html&gt;
      &lt;body&gt;
       &lt;h2&gt;Student DataBase&lt;/h2&gt;
      &lt;table border="1"&gt;
            &lt;tr&gt;
               &lt;th  bgcolor="yellow"&gt;Name&lt;/th&gt;    
        &lt;xsl:for-each select="data/student"&gt;
                          &lt;td width="200"&gt;&lt;xsl:value-of select="name"/&gt;&lt;/td&gt;
               &lt;/xsl:for-each&gt;
             &lt;/tr&gt;
            &lt;tr&gt;
               &lt;th  bgcolor="yellow"&gt;Course&lt;/th&gt;    
        &lt;xsl:for-each select="data/student"&gt;
                          &lt;td width="200"&gt;&lt;xsl:value-of select="course"/&gt;&lt;/td&gt;
        &lt;/xsl:for-each&gt;
            &lt;/tr&gt;
             &lt;tr&gt;
               &lt;th  bgcolor="yellow"&gt;Marks&lt;/th&gt;    
        &lt;xsl:for-each select="data/student"&gt;
                          &lt;td width="200"&gt;&lt;xsl:value-of select="marks"/&gt;&lt;/td&gt;
        &lt;/xsl:for-each&gt;
             &lt;/tr&gt; 
             &lt;tr&gt;
               &lt;th  bgcolor="yellow"&gt;Semester&lt;/th&gt;    
        &lt;xsl:for-each select="data/student"&gt;
                          &lt;td width="200"&gt;&lt;xsl:value-of select="sem"/&gt;&lt;/td&gt;
        &lt;/xsl:for-each&gt;
             &lt;/tr&gt;
         &lt;/table&gt;
       &lt;/body&gt;
     &lt;/html&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  
  and following student.html file
  
  &lt;html&gt;
   &lt;head&gt;
   &lt;title&gt; Testing IE &lt;/title&gt;
   &lt;script langauge="JavaScript" type="text/javascript"&gt;
    function loadXMLDoc(dname)
    {
     if (window.XMLHttpRequest)
       {
        xhttp=new XMLHttpRequest();
       }
     else
       {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     xhttp.open("GET",dname,false);
     xhttp.send("");
     return xhttp.responseXML;
    }
  
    function displayResult()
    {
     xml=loadXMLDoc("student.xml");
     xsl=loadXMLDoc("student.xsl");
     // code for IE
     if (window.ActiveXObject)
       {
        ex=xml.transformNode(xsl);
        document.getElementById("example").innerHTML=ex;
       }
  
     // code for Mozilla, Firefox, Opera, etc.
     else if (document.implementation &amp;&amp; document.implementation.createDocument)
       {
        xsltProcessor=new XSLTProcessor();
        xsltProcessor.importStylesheet(xsl);
        resultDocument = xsltProcessor.transformToFragment(xml,document);
        document.getElementById("example").appendChild(resultDocument);
       }
    }
   &lt;/script&gt;
   &lt;/head&gt;
  
   &lt;body onLoad="displayResult()"&gt;
    &lt;div id="example" /&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>