Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort on computed values

Status
Not open for further replies.

JeanineMM

Instructor
Aug 21, 2001
4
US
I am learning XML and XSL. I am building on an example I found on line (developer Works: XML zone: What kind of language is XSLT, by Michael Kay) that takes xml data with soccer scores and with two different XSL files produces two
outputs. The second output is a table with the played, won, drawn, lost, for, and against totals. I can successfully add
to this the ranking score (3 times wins, 1 times ties).
What I want to do is output the table sorted by the rankings.

The XML contains nodes like: (ignore the feature="no". I used this for the other type of display).

<match feature=&quot;no&quot;>
<date>31-May-2002 </date>
<team score=&quot;1&quot;>Senegal </team>
<team score=&quot;0&quot;>France </team>
</match>

The xsl for the unordered table follows. What I want to
do (perhaps) is create a new tree, with nodes with the computed values, and then sort on it.
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>
<xsl:transform
xmlns:xsl=&quot; version=&quot;1.0&quot;>

<xsl:eek:utput method=&quot;html&quot;/>
<xsl:variable name=&quot;teams&quot; select=&quot;//team[not(.=preceding::team)]&quot;/>
<xsl:variable name=&quot;matches&quot; select=&quot;//match&quot;/>
<xsl:template match=&quot;/results&quot;>
<html>
<head><title>Results of World Cup
</title>
<LINK REL=&quot;stylesheet&quot; TYPE=&quot;text/css&quot; HREF=&quot;results.css&quot;/>

</head>
<body>
<h2> Results of World Cup </h2>
<table cellpadding=&quot;5&quot;>
<tr>
<th> Team </th>
<th> Played </th>
<th> Won </th>
<th> Lost </th>
<th> Tied </th>
<th> For </th>
<th> Against </th>
<th> Points </th>
</tr>
<xsl:for-each select =&quot;$teams&quot;>
<xsl:variable name=&quot;this&quot; select=&quot;.&quot;/>
<xsl:variable name=&quot;played&quot; select=&quot;count($matches[team=$this])&quot;/>
<xsl:variable name=&quot;won&quot; select=&quot;count($matches[team[.=$this]/@score &gt;
team[.!=$this]/@score])&quot;/>
<xsl:variable name=&quot;lost&quot; select=&quot;count($matches[team[.=$this]/@score &lt;
team[.!=$this]/@score])&quot;/>
<xsl:variable name=&quot;tied&quot; select=&quot;count($matches[team[.=$this]/@score = team[.!=$this]/@score])&quot;/>
<xsl:variable name=&quot;for&quot; select=&quot;sum($matches/team[.=current()]/@score)&quot;/>
<xsl:variable name=&quot;against&quot; select=&quot;sum($matches[team=current()]/team/@score)-$for&quot;/>
<xsl:variable name=&quot;points&quot; select=&quot;3*$won+$tied&quot;/>
<tr>
<td><xsl:value-of select=&quot;.&quot;/></td>
<td><xsl:value-of select=&quot;$played&quot;/></td>
<td><xsl:value-of select=&quot;$won&quot;/></td>
<td><xsl:value-of select=&quot;$lost&quot;/></td>
<td><xsl:value-of select=&quot;$tied&quot;/></td>
<td><xsl:value-of select=&quot;$for&quot;/></td>
<td><xsl:value-of select=&quot;$against&quot;/></td>
<td><xsl:value-of select=&quot;$points&quot;/> </td>
</tr>

</xsl:for-each>
</table>
</body> </html>
</xsl:template>
</xsl:transform>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top