关于xml+xsl的问题!

shouni 2003-10-21 10:20:00
在jsp我用xml+xsl生成树图,出现下面的错误:
The stylesheet does not contain a document element.The
stylesheet may be empty,or it may noe be a well-formed XML document
可是当我用在asp中就不出现问题!
代码如下:
<Script language="javaScript">

//alert("<%=xmlName%>")
var xml=new ActiveXObject("Microsoft.XMLDOM");
xml.async=false;
xml.load("data.xml");
var xsl=new ActiveXObject("Microsoft.XMLDOM");
xsl.async=false;

if("<%=open%>"=="1")//全部展开
{
xsl.load("xTree_open.xsl");
}else//全部关闭
{

xsl.load("xTree.xsl");
}
document.write(xml.transformNode(xsl));

</script>

...全文
21 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shouni 2003-10-23
  • 打赏
  • 举报
回复
树图能够出来吗?
我这边怎么老出来下面的错误!!即使注释了if("<%=open%>"=="1")//全部展开
{ 也不行啊,难道是ie的问题?


The stylesheet does not contain a document element.The
stylesheet may be empty,or it may noe be a well-formed XML document
CoolAbu 2003-10-23
  • 打赏
  • 举报
回复
我把你这段Code拷到我机子上试了一下,Tomcat4.1

如果是HTML页面,没有错误
如果是JSP,下面这两个地方报错,我把它们注释掉就好了

//alert("<%=xmlName%>")

if("<%=open%>"=="1")//全部展开
{
CoolAbu 2003-10-23
  • 打赏
  • 举报
回复
你用的IE是什么版本?如果是IE5,那么把xsl的xmlns换成草案的那个。

我这里能正常显示,但不是树图。那就已经是xsl的编写问题了。
CoolAbu 2003-10-22
  • 打赏
  • 举报
回复
把你的XML和XSL贴出来看看,


有点疑问,下面这个if条件中的语句在Javascript中能执行吗?
if("<%=open%>"=="1")//全部展开
{
xsl.load("xTree_open.xsl");
}else//全部关闭


shouni 2003-10-22
  • 打赏
  • 举报
回复
为什么阿?
shouni 2003-10-22
  • 打赏
  • 举报
回复
if 语句可以执行的!!

xml:

<?xml version="1.0" encoding="gb2312"?>
<xtree target="text">
<node name="业务树图" alt="业务树图" url="dispatch.jsp?ne_label=业务树图&object_class=&int_id=" target="text" opened="0" id="1">
<node name="其它" alt="其它" url="dispatch.jsp?ne_label=其它&object_class=&int_id=9,0" target="text" opened="0" id="2">
<webpage url="dispatch.jsp?ne_label=10.0.5.112&object_class=4999&int_id=816" target="text" alt="其它" pic="images/999.gif">10.0.5.112</webpage>
<webpage url="dispatch.jsp?ne_label=10.0.9.201&object_class=4999&int_id=676" target="text" alt="其它" pic="images/999.gif">10.0.9.201</webpage>
<webpage url="dispatch.jsp?ne_label=10.0.6.24&object_class=4999&int_id=679" target="text" alt="其它" pic="images/999.gif">10.0.6.24</webpage>
<webpage url="dispatch.jsp?ne_label=10.0.201.3&object_class=4999&int_id=682" target="text" alt="其它" pic="images/999.gif">10.0.201.3</webpage>
<webpage url="dispatch.jsp?ne_label=10.0.10.15&object_class=4999&int_id=691" target="text" alt="其它" pic="images/999.gif">10.0.10.15</webpage>
<webpage url="dispatch.jsp?ne_label=10.0.0.105&object_class=4999&int_id=103" target="text" alt="其它" pic="images/999.gif">10.0.0.105</webpage>
</node>
</node>
</xtree>


xsl:

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

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

<xsl:template match="xtree">
<HTML>
<HEAD>
<xsl:if test="@target">
<base>
<xsl:attribute name="target"><xsl:value-of select="@target"/></xsl:attribute>
</base>
</xsl:if>

<SCRIPT><![CDATA[
//Open or close nodes

function SetNode(nodename) {
if (eval("documents" + nodename + ".style.display == 'none';")) {
// Open
eval("image" + nodename + ".src = 'images/minus.gif'");
eval("nodeimage" + nodename + ".src = 'images/open.gif'");
eval("documents" + nodename + ".style.display = 'block'");
}
else {
// Close
eval("image" + nodename + ".src = 'images/plus.gif'");
eval("nodeimage" + nodename + ".src = 'images/closed.gif'");
eval("documents" + nodename + ".style.display = 'none'");
}
}


]]>//</SCRIPT>
<style>A {TEXT-DECORATION: none;color:#000000}
body{
FONT-SIZE: 12px;
COLOR: #000000;
FONT-FAMILY: 宋体;
scrollbar-face-color: #DEE3E7;
scrollbar-highlight-color: #FFFFFF;
scrollbar-shadow-color: #DEE3E7;
scrollbar-3dlight-color: #D1D7DC;
scrollbar-arrow-color: #006699;
scrollbar-track-color: #EFEFEF;
scrollbar-darkshadow-color: #98AAB1;
}
td{
FONT-SIZE: 12px;
COLOR: #000000;
FONT-FAMILY: 宋体;
}
</style>
</HEAD >
<BODY background="../images/left.jpg" >
<nobr>
<xsl:apply-templates/>
</nobr>
</BODY>
</HTML>
</xsl:template>


<xsl:template match="node">

<DIV class="nodeheader">

<xsl:attribute name="id">Node<xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<table cellspacing="0" cellpadding="0"><tr>
<!-- '+' or '-' symbols for an open or closed node -->
<xsl:choose>
<xsl:when test="@opened[.='1']">
<td>
<IMG SRC="images/minus.gif">
<xsl:attribute name="id">image<xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="onClick">SetNode('<xsl:value-of select="@id"/>');</xsl:attribute>
</IMG>
</td>
<td>
<IMG SRC="images/open.gif">
<xsl:attribute name="id">nodeimage<xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="onDblClick">SetNode('<xsl:value-of select="@id"/>');</xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>

</IMG>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<IMG SRC="images/plus.gif">
<xsl:attribute name="id">image<xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="onClick">SetNode('<xsl:value-of select="@id"/>');</xsl:attribute>
</IMG>
</td>
<td>
<IMG SRC="images/closed.gif">
<xsl:attribute name="id">nodeimage<xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="onDblClick">SetNode('<xsl:value-of select="@id"/>');</xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
</IMG>
</td>
</xsl:otherwise>
</xsl:choose>

<xsl:choose>
<xsl:when test="@url">
<td>
<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:value-of select="@name"/>
</A>
</td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="@name"/></td>
</xsl:otherwise>
</xsl:choose>
</tr></table>
</DIV>

<DIV class="nodedocuments">
<xsl:attribute name="id">documents<xsl:value-of select="@id"/></xsl:attribute>

<xsl:choose>
<xsl:when test="@opened[.='1']">
<xsl:attribute name="Style">display: block; Margin-left: 16;</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="Style">display: none; Margin-left: 16;</xsl:attribute>
</xsl:otherwise>
</xsl:choose>

<xsl:apply-templates />
</DIV>
</xsl:template>

<xsl:template match="webpage">
<DIV Class="webpage">
<xsl:attribute name="Style"> Margin-left: 16;</xsl:attribute>
<IMG>
<xsl:attribute name="src"><xsl:value-of select="@pic"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
</IMG>
<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:apply-templates />
</A>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>

</DIV>
</xsl:template>

<xsl:template match="text()">
<xsl:value-of />
</xsl:template>
</xsl:stylesheet>


shouni 2003-10-21
  • 打赏
  • 举报
回复
不是吧,同样的xml和xsl文件在asp中能够实现!
flyycyu 2003-10-21
  • 打赏
  • 举报
回复
是你的xml或者xsl文件的问题!
和这段代码无关!

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧