关于XSLT的问题,十万火急,高手来帮帮忙

cclxd 2002-05-31 10:01:58
有下面的一个XML文件:
<?xml version="1.0"?>
<Match>
<Date>21/3/2005</Date><Stadium>Wembley</Stadium>
<Team Name="Liverpool">
<Goal Scorer="O'Reilly" Time="15"/>
<Goal Scorer="Smith" Time="20"/>
<Goal Scorer="O'Reilly" Time="57"/>
<Goal Scorer="Jones" Time="65"/>
<Goal Scorer="Smith" Time="78"/>
<Goal Scorer="O'Reilly" Time="88"/>
</Team>
<Team Name="Real Madrid">
<Goal Scorer="Charles" Time="48"/>
<Goal Scorer="Humble" Time="55"/>
<Goal Scorer="Santana" Time="85"/>
</Team>
</Match>

根据用户提供的队名,想要转化成一个HTML文件,包括进球者,进球数,并按照进球数降序排列。
Scorer Goals
O'Reilly 3
Smith 2
Jones 1


十万火急,那位高手来帮帮忙,最好给出XSLT的程序, 不胜感激,大分送上
...全文
40 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cclxd 2002-05-31
  • 打赏
  • 举报
回复
多谢,我来试试,可以就给分
saucer 2002-05-31
  • 打赏
  • 举报
回复
try something like:

1. score.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="scorelist.xsl" ?>
<Match>
<Date>21/3/2005</Date><Stadium>Wembley</Stadium>
<Team Name="Liverpool">
<Goal Scorer="O'Reilly" Time="15"/>
<Goal Scorer="Smith" Time="20"/>
<Goal Scorer="O'Reilly" Time="57"/>
<Goal Scorer="Jones" Time="65"/>
<Goal Scorer="Smith" Time="78"/>
<Goal Scorer="O'Reilly" Time="88"/>
</Team>
<Team Name="Real Madrid">
<Goal Scorer="Charles" Time="48"/>
<Goal Scorer="Humble" Time="55"/>
<Goal Scorer="Santana" Time="85"/>
</Team>
</Match>

2. scorelist.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="scorer" use="@Scorer" match="Goal" />
<xsl:template match="/">
<html>
<head>
<script language="javascript">
<![CDATA[
var g_param = null;
function window.onload()
{
g_param = document.XSLDocument.selectSingleNode("//xsl:param");
}

function displayScorers(sTeam)
{
g_param.setAttribute("select","'" + sTeam + "'");
document.all("dvHTML").innerHTML = document.XMLDocument.documentElement.transformNode(document.XSLDocument);
}
]]>
</script>
</head>
<body>
<form name="form1">
Team:
<select name="team" onchange="displayScorers(this.value)">
<xsl:for-each select="Match/Team">
<option value="{@Name}"><xsl:value-of select="@Name" /></option>
</xsl:for-each>
</select>
</form>
Scorers:<br />
<div id="dvHTML">
<xsl:apply-templates select="Match/Team[1]">
<xsl:with-param name="team" select="Match/Team[1]/@Name" />
</xsl:apply-templates>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="Team">
<xsl:param name="team" />
<xsl:if test="@Name = $team">
<xsl:for-each select="Goal[count(. | key('scorer',@Scorer)[1])=1]">
<xsl:sort select="count(key('scorer',@Scorer))" order="descending" />
<xsl:sort select="@Scorer" />
<xsl:value-of select="@Scorer"/>:<xsl:value-of select="count(key('scorer',@Scorer))" />
(<xsl:for-each select="key('scorer',@Scorer)">
<xsl:value-of select="@Time" />
<xsl:if test="position() != last()">,</xsl:if>
</xsl:for-each>)
<br />
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template match="Date" />
<xsl:template match="Stadium" />
</xsl:stylesheet>

8,906

社区成员

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

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