coldlemon0
小狐狸
小狐狸
  • UID15611
  • 注册日期2006-11-10
  • 最后登录2006-11-13
  • 发帖数2
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:1516回复:1

firefox xml解析的诡异问题!帮忙啊

楼主#
更多 发布于:2006-11-10 11:15
我的代码实现效果为,点击testXml按钮应该显示出xml文本中存储的信息
但,在firefox中,点击没有任何效果,并且错误控制台没有任何错误输出,如果增加一个alert (alert("a")的注释去掉即可),便可正常显示,请高手指点。代码如下:

testXml.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>xml test</title>
<script language='JavaScript' type="text/javascript">
//<![CDATA[
   function showXml(id){
    var mnpdtXml = document.implementation.createDocument("", "", null);
    var div = document.getElementById(id);
    var html;
    var mnpdtXsl = document.implementation.createDocument("", "", null);
    mnpdtXsl.async = true;
    mnpdtXsl.load("framesmenu.xslt");
    mnpdtXml.async = true;
    mnpdtXml.load("framesmenudata.xml");
    var xslProc = new XSLTProcessor();
   xslProc.importStylesheet(mnpdtXsl);
    //alert("a");  ---committed and the code has no response
    div.appendChild(xslProc.transformToFragment(mnpdtXml, document));
   }
//]]>
</script>
</head>
<body>
<div id="rootDiv"></div>
<input type="button" onclick = "showXml('rootDiv')" value="testXml"/>
</body>
</html>

framesmenu.xslt:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="menu">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="submenu">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="item">
<div>
<xsl:if test="@guid">
<xsl:attribute name="id">g<xsl:value-of select="@guid" /></xsl:attribute>
<xsl:attribute name="expanded">false</xsl:attribute>
</xsl:if>
<span>
<xsl:choose>
<xsl:when test="@guid">
<div onclick="toggle(this.parentNode.parentNode)"><span>+</span></div>
</xsl:when>
<xsl:when test="@icon">
<img>
<xsl:attribute name="src"><xsl:value-of select="@icon"/></xsl:attribute>
</img>
</xsl:when>
<xsl:otherwise>
<div><span>.</span></div>
</xsl:otherwise>
</xsl:choose>
</span>
<span onclick="toggle(this.parentNode);activate(this.parentNode)">
<xsl:attribute name="title"><xsl:value-of select="@label" /></xsl:attribute>
<xsl:choose>
<xsl:when test="@url">
<a>
<xsl:attribute name="href"><xsl:value-of select="@url" /></xsl:attribute>
<xsl:if test="@target"><xsl:attribute name="target"><xsl:value-of select="@target" /></xsl:attribute></xsl:if>
              <xsl:if test="not(@target)">
                <xsl:attribute name="target">MNPMainFrame</xsl:attribute>
              </xsl:if>
<xsl:value-of select="@label" />
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@label" />
</xsl:otherwise>
</xsl:choose>
</span>
</div>
<xsl:if test="@guid">
<div style="display:none">
<xsl:apply-templates />
</div>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

framesmenudata.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<submenu dir="LTR" guid="ed266784-d40f-4c46-96ce-b111cd84ac93" label="网络与目录服务" url="/china/MSDN/library/NetComm/default.mspx">
<item label="Internet Explorer 6 中的 CSS 增强功能" url="http://www.baidu.com"></item>
<item label="Internet 开发术语表" url="http://www.baidu.com"></item>
<item label="深情告别(Web Team 访谈)" url="http://www.baidu.com"></item>
</submenu>
coldlemon0
小狐狸
小狐狸
  • UID15611
  • 注册日期2006-11-10
  • 最后登录2006-11-13
  • 发帖数2
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
1楼#
发布于:2006-11-10 11:15
自己顶啊!!
游客

返回顶部