请问如何在一个XSL中让一个XML有不同的视图?

noho 2001-07-23 05:22:40
加精
比如
<music author="罗大佑" name="鹿港小镇"/>
<music author="罗大佑" name="家I"/>
<music author="罗大佑" name="家II"/>
<music author="齐秦" name="丝路"/>
<music author="齐秦" name="火柴天堂"/>

现在要求有三个视图
第一个视图显示所有的歌曲
第二个视图显示罗大佑的歌曲
第三个视图显示齐秦的歌曲

这种情况下XSL该如何写?
请不吝赐教。
...全文
120 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
noho 2001-08-04
  • 打赏
  • 举报
回复
多谢!
karma 2001-07-31
  • 打赏
  • 举报
回复
cd.xml:
<?xml-stylesheet type="text/xsl" href="cd.xsl" ?>
<library>
<cd>
<music author="罗大佑" name="鹿港小镇"/>
<music author="罗大佑" name="家I"/>
<music author="罗大佑" name="家II"/>
<music author="齐秦" name="丝路"/>
<music author="齐秦" name="火柴天堂"/>
</cd>
</library>

cd.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<script language="javascript">
var oParam, xmldoc, xsldoc;
function init()
{
xmldoc = document.XMLDocument.documentElement;
xsldoc = document.XSLDocument;
oParam = xsldoc.selectSingleNode("//xsl:param");
}


function setCDSel(sAuthor)
{
var sParam = "*";
if (sAuthor != "")
{
sParam += "[@author='" + sAuthor + "']";
}
oParam.setAttribute("select",sParam);
cdlist.innerHTML = xmldoc.transformNode(xsldoc);
}

</script>
</head>
<body onload="init()">
<div id="cdlist"><xsl:apply-templates /></div>
<input type="button" value="Show All" onclick="setCDSel('')" />
<input type="button" value="Show 罗大佑" onclick="setCDSel('罗大佑')" />
<input type="button" value="Show 齐秦" onclick="setCDSel('齐秦')" />
</body>
</html>
</xsl:template>

<xsl:template match="cd">
<xsl:param name="cdlist" select="*" />
<xsl:apply-templates select="$cdlist" />
</xsl:template>

<xsl:template match="music">
<xsl:value-of select="@author" />:<xsl:value-of select="@name" /><br/>
</xsl:template>

</xsl:stylesheet>
noho 2001-07-30
  • 打赏
  • 举报
回复
to housetea
我的意思是
<library>
<cd>
<music author="罗大佑" name="鹿港小镇"/>
<music author="罗大佑" name="家I"/>
<music author="罗大佑" name="家II"/>
<music author="齐秦" name="丝路"/>
<music author="齐秦" name="火柴天堂"/>
</cd>
</library>

现在要求有三个视图
第一个视图显示所有的歌曲
第二个视图显示罗大佑的歌曲
第三个视图显示齐秦的歌曲

怎样写一个xsl实现三个视图?
noho 2001-07-30
  • 打赏
  • 举报
回复
那就是说只能用微软的parser了?
如果用的不是微软的parser
请问如何解决?
多谢!
hifar 2001-07-24
  • 打赏
  • 举报
回复
<xsl:template
name= Qname
match = pattern
priority = "number"
mode = Qname
</xsl:template>
如果用的是微软的parser 可以用 name 来区分
housetea 2001-07-24
  • 打赏
  • 举报
回复
?
不明白你指什么
noho 2001-07-23
  • 打赏
  • 举报
回复
<library>
<cd>
<music author="罗大佑" name="鹿港小镇"/>
<music author="罗大佑" name="家I"/>
<music author="罗大佑" name="家II"/>
<music author="齐秦" name="丝路"/>
<music author="齐秦" name="火柴天堂"/>
</cd>
</library>

<xsl:template match="library">这样的template只能有一个吧?

8,906

社区成员

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

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