Subject: Re: [xsl] Grouping and calculating a score list From: omprakash.v@xxxxxxxxxxxxx Date: Mon, 6 Feb 2006 19:51:20 +0530 |
Hi, Here's another solution that returns all the players in all the calls to results template. You would have to verify the validity of the scores though. Basically, the playerlist is now a global variable as opposed to being passed in as a param. cheers, prakash <?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:variable name="playerList" select="//match/player"/> <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="tableID" select="concat('results_' , @date)"/> </xsl:call-template> </xsl:template> <xsl:template name="displayPlayerSummary"> <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> </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 > 10])"/></td> </tr> </xsl:for-each> </tbody> </table> </xsl:template> </xsl:stylesheet> Volker Witzel <v.witzel@xxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > cc: (bcc: omprakash.v/Polaris) Subject: [xsl] Grouping and calculating a score list 02/06/2006 03:06 PM Please respond to xsl-list 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> </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 > 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 This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited. Visit Us at http://www.polaris.co.in
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping and calculating , Juergen | Thread | [xsl] Grouping and calculating a sc, Volker Witzel |
Re: [xsl] Grouping and calculating , Juergen | Date | [xsl] Parse through a table in XPat, Dariusz Borowski |
Month |