【发布时间】:2014-02-11 22:53:39
【问题描述】:
我正在尝试以表格格式显示静态信息或使用函数计算的信息。
基本上我有几场比赛的一些球队统计数据,有一支主队和一支客队,只有状态为“已参加”的比赛才应计入比分,但我需要将它们显示在按以下排名的表格中他们的胜利。
这里是 XML
<Schedule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Teams>
<Team>Blue Jays</Team>
</Teams>
<Game>
<Home_Team>Blue Jays</Home_Team>
<Away_Team>Marlins</Away_Team>
<Date>2012-01-10</Date>
<Home_Team_Score>7</Home_Team_Score>
<Away_Team_Score>9</Away_Team_Score>
</Game>
这是我试图显示表格的 XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0"/>
<xsl:key name="team" match="Teams" use="Team"/>
<xsl:template match="/Schedule">
<html>
<head>
<title><xsl:value-of select="League"/>
</title>
<link href="batty.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<xsl:apply-templates select="headliner"/>
</body>
</html>
</xsl:template>
<xsl:template match="headliner">
<h1>
<xsl:value-of select="League"/>
</h1>
<h5>
<th>put date here</th>
</h5>
<xsl:apply-templates select="scoreboard"/>
</xsl:template>
<xsl:template match="scoreboard">
<table cellspacing="1" cellpadding="2" id="scores">
<tr class="title">
<th colspan="22">Season <xsl:value-of select="//Schedule[@season]"/></th>
</tr>
<tr class="fields">
<th style="text-align: left">Team</th>
<th>Rank</th>
<th>Wins</th>
<th>Losses</th>
<th>Ties</th>
<th>Points Earned</th>
<th>Points Against</th>
<th>Win %</th>
<th>Games Behind</th>
</tr>
<tr class="rankingTeams">
<xsl:call-template name="calcScores">
</xsl:call-template>
</tr>
</table>
</xsl:template>
<xsl:template name="calcScores">
<xsl:variable name="wins" />
<xsl:variable name="losses" />
<xsl:variable name="ties" />
<xsl:variable name="pointsEarned" />
<xsl:variable name="winPercentage" />
<xsl:variable name="gamesBehind" />
<xsl:for-each
select="//Teams[generate-id()=generate-id(key('team', Team)[1])]">
<xsl:sort select="Team" />
<h1><xsl:value-of select="Team" /></h1>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我什至无法显示表格。我可以将记分板模板中的代码直接放在正文中,它会显示,但不是调用模板时的方式。
然后我不确定如何在我的 for-each 循环中计算输赢等
【问题讨论】:
-
看起来你的 XML 在中间被切断了,只在一场比赛之后并且没有关闭
<Schedule>标签。你能发布一个更完整的例子吗? -
我刚刚发布了一个完整的“游戏”元素以缩短篇幅。它只是不断重复不同的“游戏”元素,并以 标签结束。
-
嗯,很高兴看到更多,所以我们可以有一些东西来测试。