关于XML根结点的问题:

cer 2003-12-08 09:15:03
XML文件如下:
=========================================================================
<?xml version="1.0" encoding="GB2312"?>
<所有人物>
<人物>
<姓名>张无忌</姓名>
</人物>
<人物>
<姓名>伟小宝</姓名>
</人物>
</所有人物>
=========================================================================

XSL文件一:
=========================================================================
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="所有人物">
<html>
<head>
<title>我们的第一个xml例子</title>
</head>
<body>
<table width="100%">
<xsl:apply-templates select="人物"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="人物">
<tr>
<xsl:value-of select="./姓名"/>
</tr>
</xsl:template>
</xsl:stylesheet>
=========================================================================


XSL文件二:
=========================================================================
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head>
<title>我们的第一个xml例子</title>
</head>
<body>
<table width="100%">
<xsl:apply-templates select="人物"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="人物">
<tr>
<xsl:value-of select="./姓名"/>
</tr>
</xsl:template>
</xsl:stylesheet>
=========================================================================


这两个XSL文件的区别只是将“/”换成了“所有人物”为什么输出给果不一样,难道“所有人物”不是根结点吗?
...全文
49 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
colee 2003-12-08
  • 打赏
  • 举报
回复
以"/"开头的位置路径是绝对路径, 没有"/"开头的是相对路径!
第二个XSL文件要改:
<xsl:apply-templates select="人物"/>
=>
<xsl:apply-templates select="所有人物/人物"/>
cer 2003-12-08
  • 打赏
  • 举报
回复
自已顶一下

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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