统计玩家在不同难度下玩游戏的次数
Count the number of times a player plays a game in a different difficulty level
我有一个 xml 和如下所示的 xslt 文件。我在 table 中显示了游戏名称和玩家名称。但现在我正在尝试做一件事,但我不知道该怎么做。
我想显示一个玩家在新手,简单,中等,困难,传奇级别和总计中玩了多少次游戏。例如,我希望每一行都是这样的:
GameName | Player Name | NoviceLevels | EasyLevels | MediumLevels | HardLevels | Total
我已经尝试了很多替代方案,但我没有成功地把这个工作成这样。你知道如何做到这一点吗?
<games>
<game>
<gamename>GameTitle 1</gamename>
<players>
<player>
<playername>John</playername>
<difficultlevel>Novice</difficultlevel>
<duration>130</duration>
</player>
<player>
<playername>John</playername>
<difficultlevel>Easy</difficultlevel>
<duration>210</duration>
</player>
<player>
<playername>Zed</playername>
<difficultlevel>Medium</difficultlevel>
<duration>300</duration>
</player>
</players>
</game>
</games>
还有这个 xslt:
<table>
<xsl:for-each select="//games">
<tr>
<th>GameName</th>
<th>Player</th>
<th>Beginner</th>
<th>Beginner</th>
<th>Medium</th>
<th>Hard</th>
<th>Legend</th>
<th>Total</th>
</tr>
<xsl:for-each select="game">
<tr>
<td><xsl:value-of select="gamename"/></td>
<td><xsl:value-of select="players/player/playername"/></td>
....???
</tr>
</xsl:for-each>
</table>
这里是你尝试过的改编,假设 XSLT 2.0 处理器使用 for-each-group
:
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="2.0">
<table>
<tr>
<th>GameName</th>
<th>Player</th>
<th>NoviceLevels</th>
<th>EasyLevels</th>
<th>Medium</th>
<th>Hard</th>
<th>Legend</th>
<th>Total</th>
</tr>
<xsl:for-each select="games/game">
<xsl:for-each-group select="players/player" group-by="playername">
<tr>
<td><xsl:value-of select="ancestor::game/gamename"/></td>
<td><xsl:value-of select="playername"/></td>
<td><xsl:value-of select="current-group()[difficultlevel = 'Novice']/duration"/></td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td><xsl:value-of select="sum(current-group()/duration)"/></td>
</tr>
</xsl:for-each-group>
</xsl:for-each>
</table>
</html>
我还没有把所有 table 单元格的代码分别拼出来,我希望从拼出的一层中应该清楚如何做到这一点。
我也不确定显示的方法是否足够,它假设任何玩家每场比赛的每个难度级别只有一个条目,否则,您需要使用 difficultylevel
的嵌套分组.
我有一个 xml 和如下所示的 xslt 文件。我在 table 中显示了游戏名称和玩家名称。但现在我正在尝试做一件事,但我不知道该怎么做。
我想显示一个玩家在新手,简单,中等,困难,传奇级别和总计中玩了多少次游戏。例如,我希望每一行都是这样的:
GameName | Player Name | NoviceLevels | EasyLevels | MediumLevels | HardLevels | Total
我已经尝试了很多替代方案,但我没有成功地把这个工作成这样。你知道如何做到这一点吗?
<games>
<game>
<gamename>GameTitle 1</gamename>
<players>
<player>
<playername>John</playername>
<difficultlevel>Novice</difficultlevel>
<duration>130</duration>
</player>
<player>
<playername>John</playername>
<difficultlevel>Easy</difficultlevel>
<duration>210</duration>
</player>
<player>
<playername>Zed</playername>
<difficultlevel>Medium</difficultlevel>
<duration>300</duration>
</player>
</players>
</game>
</games>
还有这个 xslt:
<table>
<xsl:for-each select="//games">
<tr>
<th>GameName</th>
<th>Player</th>
<th>Beginner</th>
<th>Beginner</th>
<th>Medium</th>
<th>Hard</th>
<th>Legend</th>
<th>Total</th>
</tr>
<xsl:for-each select="game">
<tr>
<td><xsl:value-of select="gamename"/></td>
<td><xsl:value-of select="players/player/playername"/></td>
....???
</tr>
</xsl:for-each>
</table>
这里是你尝试过的改编,假设 XSLT 2.0 处理器使用 for-each-group
:
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="2.0">
<table>
<tr>
<th>GameName</th>
<th>Player</th>
<th>NoviceLevels</th>
<th>EasyLevels</th>
<th>Medium</th>
<th>Hard</th>
<th>Legend</th>
<th>Total</th>
</tr>
<xsl:for-each select="games/game">
<xsl:for-each-group select="players/player" group-by="playername">
<tr>
<td><xsl:value-of select="ancestor::game/gamename"/></td>
<td><xsl:value-of select="playername"/></td>
<td><xsl:value-of select="current-group()[difficultlevel = 'Novice']/duration"/></td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td><xsl:value-of select="sum(current-group()/duration)"/></td>
</tr>
</xsl:for-each-group>
</xsl:for-each>
</table>
</html>
我还没有把所有 table 单元格的代码分别拼出来,我希望从拼出的一层中应该清楚如何做到这一点。
我也不确定显示的方法是否足够,它假设任何玩家每场比赛的每个难度级别只有一个条目,否则,您需要使用 difficultylevel
的嵌套分组.