我一直在努力寻找如何获取游戏结果(团队和最终分数)的XML文件,并生成一个团队排名列表,显示每个团队以及他们赢得,输掉或绑定的次数。结果也应该按总胜分排序,但我甚至无法找出计算胜负的一个好方法,更不用说按结果排序了。我知道它必须涉及muenchian分组,并且我已经编写了可以找到所有不同团队的部分,但却难以从那里发展。任何帮助将不胜感激。使用XSLT muenchian分组来计算运动队积分(赢/输)?
games.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="games.xsl"?>
<Games>
<Game>
<Home>Team A</Home>
<Away>Team B</Away>
<Home_Score>20</Home_Score>
<Away_Score>15</Away_Score>
</Game>
<Game>
<Home>Team C</Home>
<Away>Team D</Away>
<Home_Score>12</Home_Score>
<Away_Score>18</Away_Score>
</Game>
<Game>
<Home>Team A</Home>
<Away>Team C</Away>
<Home_Score>8</Home_Score>
<Away_Score>8</Away_Score>
</Game>
<Game>
<Home>Team B</Home>
<Away>Team D</Away>
<Home_Score>6</Home_Score>
<Away_Score>14</Away_Score>
</Game>
<Game>
<Home>Team D</Home>
<Away>Team C</Away>
<Home_Score>9</Home_Score>
<Away_Score>11</Away_Score>
</Game>
<Game>
<Home>Team C</Home>
<Away>Team A</Away>
<Home_Score>13</Home_Score>
<Away_Score>13</Away_Score>
</Game>
</Games>
games.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Key for identifying teams -->
<xsl:key name="unique-teams" match="/Games/Game" use="Home" />
<xsl:template match="/">
<html>
<head>
<title>Team Standings</title>
</head>
<body>
<!-- Get distinct teams, sort by team name -->
<xsl:apply-templates select="//Game[generate-id() = generate-id(key('unique-teams', Home)[1])]">
<xsl:sort select="Home" />
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="Game">
<!-- Current team -->
<xsl:variable name="selectedteam" select="Home" />
<!-- Output each unique team name to the screen -->
<h1><xsl:value-of select="$selectedteam"/></h1>
<!-- Loop through all games to calculate totals??? -->
<xsl:for-each select="//Game">
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
山姆J.,是我的回答对你有用? – 2012-02-23 21:05:05