如何在 IE8 中通过 onLoad() 渲染多个 XSLT 文件

发布于 2024-11-05 18:52:34 字数 2104 浏览 0 评论 0原文

只是为了练习,我尝试在页面上的两个不同位置呈现相同的标记。它在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋意浓 2024-11-12 18:52:34

有一种更简单的方法 :)

安装 Microsoft 的 XML 工具 - http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17280

然后在您的桌面名称上创建您的 XSL - 示例test.xsl

<?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="/">
    <xsl:value-of select="/root"/>
</xsl:template>
</xsl:stylesheet>

对应 - 桌面上的test.xml

<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>foo</root>

在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

<?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="/">
    <xsl:value-of select="/root"/>
</xsl:template>
</xsl:stylesheet>

Corresponding - test.xml on the desktop

<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>foo</root>

Open test.xml in IE and the XSLT transformation should have been done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文