i have a xml file like so: Code: <results group="A"> <match> <date>10-Jun-98</date> <team score="2">Brazil</team> <team score="1">Scotland</team> </match> <match> <date>10-Jun-98</date> <team score="2">Morocco</team> <team score="2">Norway</team> </match> ....... </results> and an unfinished xquery query like so: Code: <table> <tr> <td>team</td> <td>played</td> <td>won</td> <td>drawn</td> <td>lost</td> <td>for</td> <td>against</td> </tr> { for $team in distinct-values(doc("soccer.xml")/results/match/team) let $matches := doc("soccer.xml")/results/match[team = $team] return <tr> <td>{$team}</td> <td>{fn:count($matches)}</td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> } </table> the problem is getting the other values than the ones in it already like the goals done, i have no idea how to reference the actual scores and count them instead of counting the amount of results of scores { $results[team = $team][@score] } etc i've tried with no results at all