我创建了一个 Practice.xsl 文件来将源 Practice.xml 从 javascript 转换为 html,并将生成的 html 添加到 n 个空的 DIV 元素,这在 IE 上运行良好但相同的 html 在 Firefox 上无法正确呈现。
这是练习.xml
<feed>
<feedback>
<user>Naresh</user>
<date>12 Oct, 2009</date>
<comments>This blog has no stuff to rate it</comments>
</feedback>
<feedback>
<user>Pokuri</user>
<date>21 Dec, 2009</date>
<comments>Naresh is right</comments>
</feedback>
<feedback>
<user>Subbu</user>
<date>30 Dec, 2009</date>
<comments>I don't agree with both Naresh n Pokuri</comments>
</feedback>
</feed>
这是练习.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html" indent="yes"/>
<xsl:template match="feed/feedback">
<html>
<head>
<title>Feedback Forum</title>
</head>
<body>
<span style="display:block; padding: 5px 10px; background-color: #C9F0F9; width: 100%; margin-top:10px; border-left:10px solid #F9EBC9; border-bottom: 1px solid #000000;"><xsl:apply-templates select="user"/> on <xsl:apply-templates select="date"/></span>
<span style="display:block; padding: 5px 10px; background-color: #CDF5CD; width: 100%; border-left:10px solid #F9EBC9;"><xsl:apply-templates select="comments"/></span>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这是用于在 Firefox 上进行 XSLT 转换的 javascript
function listOrders(){
var XSLT = loadXSLT("Practice.xsl");
var trasformedText;
if(window.ActiveXObject){
trasformedText = XMLDOM.transformNode(XSLT);
document.getElementById("rightDIV").innerHTML=trasformedText;
} else if(document.implementation && document.implementation.createDocument){
**xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(XSLT);
trasformedText = xsltProcessor.transformToFragment(XMLDOM, document);
document.getElementById("rightDIV").appendChild(trasformedText);**
} else {
alert("Sorry your browser may not support xsl transformation.\n+Please check your browser documentation for further help");
}
}
供专业人员轻松识别问题的相关图像
在 Firefox 中:http: //img97.imageshack.us/img97/8509/firefoxk.jpg