如何在 IE8 中通过 onLoad() 渲染多个 XSLT 文件
只是为了练习,我尝试在页面上的两个不同位置呈现相同的标记。它在 FF Opera 等中运行良好,但在 IE8 中则不然。
有更好的方法吗?怜悯我刚刚开始 xslt
这是 js:
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}
// code for Mozilla, Firefox, Opera, etc.
else
{
xhttp=new XMLHttpRequest();
xhttp.open("GET",fname,false);
xhttp.send("");
return xhttp.responseXML;
}
}
function displayResult()
{
xmlcd=loadXMLDoc("cdcatalog.xml");
xslcd=loadXMLDoc("cdcatalog.xsl");
if (window.ActiveXObject)
{
exs=xmlcd.transformNode(xslcd);
document.getElementById("example").innerHTML=exs;
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
exs=xmlcd.transformNode(xslcd);
document.getElementById("eexample").innerHTML=exs;
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xslcd);
resultDocument = xsltProcessor.transformToFragment(xmlcd,document);
document.getElementById("example").appendChild(resultDocument);
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xslcd);
resultDocument = xsltProcessor.transformToFragment(xmlcd,document);
document.getElementById("eexample").appendChild(resultDocument);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(displayResult);
这是标记:
<html>
<head>
<script>
include myscripts
</script>
</head>
<body onload="displayResult()">
<div id="example" />
<div id="eexample" />
</body>
</html>
Just for practice i am trying to render the same markup in two different places on a page. It works fine in FF opera etc but not in IE8.
Is there a better way to do this? have mercy i just started xslt
Here is the js:
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}
// code for Mozilla, Firefox, Opera, etc.
else
{
xhttp=new XMLHttpRequest();
xhttp.open("GET",fname,false);
xhttp.send("");
return xhttp.responseXML;
}
}
function displayResult()
{
xmlcd=loadXMLDoc("cdcatalog.xml");
xslcd=loadXMLDoc("cdcatalog.xsl");
if (window.ActiveXObject)
{
exs=xmlcd.transformNode(xslcd);
document.getElementById("example").innerHTML=exs;
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
exs=xmlcd.transformNode(xslcd);
document.getElementById("eexample").innerHTML=exs;
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xslcd);
resultDocument = xsltProcessor.transformToFragment(xmlcd,document);
document.getElementById("example").appendChild(resultDocument);
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xslcd);
resultDocument = xsltProcessor.transformToFragment(xmlcd,document);
document.getElementById("eexample").appendChild(resultDocument);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(displayResult);
And here is the markup:
<html>
<head>
<script>
include myscripts
</script>
</head>
<body onload="displayResult()">
<div id="example" />
<div id="eexample" />
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一种更简单的方法 :)
安装 Microsoft 的 XML 工具 - http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17280
然后在您的桌面名称上创建您的 XSL - 示例
test.xsl
对应 - 桌面上的test.xml
在IE中打开test.xml,XSLT转换应该已经完成了。
There is a simpler way :)
Install the XML tool from Microsoft - http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17280
Then create your XSL - example - on your desktop name
test.xsl
Corresponding - test.xml on the desktop
Open test.xml in IE and the XSLT transformation should have been done.