[xsl] Grouping and calculating a score list

Subject: [xsl] Grouping and calculating a score list
From: Volker Witzel <v.witzel@xxxxxx>
Date: Fri, 10 Feb 2006 08:40:09 +0100
Dear all,

I'm trying to maintain a score list of a table tennis team in XML and
use XSLT to transform it to HTML. I'd also like to run it it with the
browser's XSL transformer, no addtl. server-side software can be used
and I'm currently limited to XSLT 1.0.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="T3Crew.xsl"?>
<T3Crew xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      <results date="2005-11-01">
              <player id="OLG" score="11"/>
              <player id="MT" score="5"/>
              <player id="MT" score="11"/>
              <player id="JH" score="9"/>
      <results date="2005-10-18">
              <player id="OLG" score="11"/>
              <player id="MT" score="7"/>
              <player id="OLG" score="11"/>
              <player id="JH" score="2"/>
              <player id="OLG" score="9"/>
              <player id="VW" score="11"/>

<?xml version="1.0" encoding="UTF-8"?>
      <player id="OLG" name="OLG Name" aka="Olli"/>
      <player id="MT" name="MT Name" aka="Mark"/>
      <player id="JH" name="JH Name" aka="Joe"/>
      <player id="VW" name="VW Name" aka="Volker"/>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	<xsl:output method="html" indent="yes" encoding="ISO-8859-1"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	<xsl:key name="players-by-id" match="match/player" use="@id"/>
	<xsl:strip-space elements="*"/>
	<xsl:variable name="playerDoc" select="document('T3Crew_Players.xml')"/>
	<xsl:template match="/">
				<h2>T3Crew - Hall of Fame<br/>(after <xsl:value-of
select="count(T3Crew/results)"/> Evevnings)</h2>
				<xsl:apply-templates select="T3Crew"/>
	<xsl:template match="T3Crew">
		<xsl:call-template name="displayPlayerSummary">
			<xsl:with-param name="tableID" select="'results_HOF'"/>
		<xsl:apply-templates select="results"/>

	<xsl:template match="results">
		<h2>Result from  <xsl:value-of select="@date"/>	</h2>
		<xsl:call-template name="displayPlayerSummary">
			<xsl:with-param name="playerList" select="./match/player"/>
			<xsl:with-param name="tableID" select="concat('results_' , @date)"/>

	<xsl:template name="displayPlayerSummary">
		<xsl:param name="playerList" select="//match/player"/>
		<xsl:param name="tableID" select="'tableID'"/>
		<table class="sortable" id="{$tableID}">
				<th># Matches</th>
			<xsl:for-each select="$playerList[count(. | key('players-by-id',
@id)[1]) = 1]">
				<xsl:sort select="@id"/>
				<xsl:variable name="id" select="@id"/>
				<td><xsl:value-of select="$playerDoc/players/player[@id =
				<td class="number"><xsl:value-of
				<td class="number"><xsl:value-of select="count($playerList[@id=$id
and @score &gt; 10])"/></td>


My problem is that the loop over the distinct players works only while processing the first result block and <xsl:for-each select="*$playerList[count(. | key('players-by-id', @id)[1]) = 1]*"> is simply an empty node set on the second iteration.

I really took my time to get a grip on this, but it seems that I reached
my XSL limit here. Any help greatly appreciated - otherwise I'd need to
go for a sports without scores ;-)


Current Thread