Re: [xsl] Grouping and calculating a score list

Subject: Re: [xsl] Grouping and calculating a score list
From: António Mota <amsmota@xxxxxxxxx>
Date: Fri, 10 Feb 2006 15:39:33 +0000
That's strange, when i was a ping-pong player, matches ended at 21!

Taking a quick look at your code, i recall someone saying that
frequetly uses of xsl:call-templates and xsl:for-each was a sign of a
not-well designed transformation, it seems to indicate the author is
"thinking procedurely", that it's not the "way" to think in xslt,
where one should think "declarativly"... Or something like that...

I don't have my xslt tools here, but by monday i can test you xslt and
suggest some changes, if you don't solve your problem till there...



On 10/02/06, Volker Witzel <v.witzel@xxxxxx> wrote:
> 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.
>
> *XMLs*
> _T3Crew.xsl_
> <?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";
> xsi:noNamespaceSchemaLocation="T3Crew.xsd">
>        <results date="2005-11-01">
>            <match>
>                <player id="OLG" score="11"/>
>                <player id="MT" score="5"/>
>            </match>
>            <match>
>                <player id="MT" score="11"/>
>                <player id="JH" score="9"/>
>            </match>
>            ...
>        </results>
>        <results date="2005-10-18">
>            <match>
>                <player id="OLG" score="11"/>
>                <player id="MT" score="7"/>
>            </match>
>            <match>
>                <player id="OLG" score="11"/>
>                <player id="JH" score="2"/>
>            </match>
>            <match>
>                <player id="OLG" score="9"/>
>                <player id="VW" score="11"/>
>            </match>
>            ...
>        </results>
> </T3Crew>
>
> _T3Crew_Players.xml_
> <?xml version="1.0" encoding="UTF-8"?>
> <players>
>        <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"/>
> </players>
>
> *Stylesheet*
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="1.0">
>         <xsl:output method="html" indent="yes" encoding="ISO-8859-1"
> doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
> doctype-system="http//www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
>         <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="/">
>                 <html>
>                         <body>
>                                 <h2>T3Crew - Hall of Fame<br/>(after
<xsl:value-of
> select="count(T3Crew/results)"/> Evevnings)</h2>
>                                 <xsl:apply-templates select="T3Crew"/>
>                         </body>
>                 </html>
>         </xsl:template>
>
>         <xsl:template match="T3Crew">
>                 <xsl:call-template name="displayPlayerSummary">
>                         <xsl:with-param name="tableID"
select="'results_HOF'"/>
>                 </xsl:call-template>
>                 <xsl:apply-templates select="results"/>
>         </xsl:template>
>
>         <xsl:template match="results">
>                 <hr/>
>                 <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:call-template>
>         </xsl:template>
>
>         <xsl:template name="displayPlayerSummary">
>                 <xsl:param name="playerList" select="//match/player"/>
>                 <xsl:param name="tableID" select="'tableID'"/>
>                 <table class="sortable" id="{$tableID}">
>                 <tbody>
>                         <tr>
>                                 <!--<th>Platz</th>-->
>                                 <th>Name</th>
>                                 <th># Matches</th>
>                                 <th>Score</th>
>                         </tr>
>
>
>                         <xsl:for-each select="$playerList[count(. |
key('players-by-id',
> @id)[1]) = 1]">
>                                 <xsl:sort select="@id"/>
>                                 <xsl:variable name="id" select="@id"/>
>                         <tr>
>                                 <!--<td>&#160;</td>-->
>                                 <td><xsl:value-of
select="$playerDoc/players/player[@id =
> $id]/@aka"/></td>
>                                 <td class="number"><xsl:value-of
> select="count($playerList[@id=$id])"/></td>
>                                 <td class="number"><xsl:value-of
select="count($playerList[@id=$id
> and @score &gt; 10])"/></td>
>                         </tr>
>                         </xsl:for-each>
>                 </tbody>
>                 </table>
>         </xsl:template>
>         </xsl:stylesheet>
>
>
> ---------8<-----
>
>
> 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 ;-)
>
> //Volker

Current Thread