我有以下三個文件,它應該做的是取出xml和xsl文件並根據它們處理它們並在瀏覽器中顯示結果。但現在的問題是,當我雙擊Chrome和IE7的HTML,我都得到了空白頁。任何人都可以告訴爲什麼它是這樣的,以及執行xslt文件並在網頁上顯示結果的正確方法是什麼?非常感謝。如何在網頁上執行並顯示xslt結果?
student.xml file
<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
<student>
<name>Bitu Kumar</name>
<course>MCA</course>
<sem>6</sem>
<marks>80</marks>
</student>
<student>
<name>Santosh Kumar</name>
<course>MCA</course>
<sem>5</sem>
<marks>70</marks>
</student>
<student>
<name>Ashish</name>
<course>M.Sc.</course>
<sem>4</sem>
<marks>80</marks>
</student>
<student>
<name>Mahesh</name>
<course>MA</course>
<sem>3</sem>
<marks>80</marks>
</student>
</data>
and following student.xsl file
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Student DataBase</h2>
<table border="1">
<tr>
<th bgcolor="yellow">Name</th>
<xsl:for-each select="data/student">
<td width="200"><xsl:value-of select="name"/></td>
</xsl:for-each>
</tr>
<tr>
<th bgcolor="yellow">Course</th>
<xsl:for-each select="data/student">
<td width="200"><xsl:value-of select="course"/></td>
</xsl:for-each>
</tr>
<tr>
<th bgcolor="yellow">Marks</th>
<xsl:for-each select="data/student">
<td width="200"><xsl:value-of select="marks"/></td>
</xsl:for-each>
</tr>
<tr>
<th bgcolor="yellow">Semester</th>
<xsl:for-each select="data/student">
<td width="200"><xsl:value-of select="sem"/></td>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
and following student.html file
<html>
<head>
<title> Testing IE </title>
<script langauge="JavaScript" type="text/javascript">
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 && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(resultDocument);
}
}
</script>
</head>
<body onLoad="displayResult()">
<div id="example" />
</body>
</html>