Count the number of times a player plays a game in a different difficulty level

Here should go questions about transforming XML with XSLT and FOP.
Azzo
Posts: 1
Joined: Thu Oct 13, 2016 8:04 pm

Count the number of times a player plays a game in a different difficulty level

Post by Azzo »

I have a xml and xslt files like below. And Im showing in a table the gamename and the player name. But now Im trying to do one thing and Im not see how.

I want to show how many times a player played a game in a novice, easy, medium, hard, legend level and the total. For example I want each row like this:

GameName | Player Name | NoviceLevels | EasyLevels | MediumLevels | HardLevels | Total

Game Title 1 John 1 1 0 0 2
I already try a lot of alternatives but Im not having success put this working like this. Do you see how to achieve this?

This is the xml:

Code: Select all

<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>
This is the XSL:

Code: Select all

<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>
What I have is here: http://xsltransform.net/pPJ8LVb/1

What Im trying now is here: http://xsltransform.net/pPJ8LVb/4

Do you know if its possible do this with xsl and what is missing in http://xsltransform.net/pPJ8LVb/4?