Вы хотите что-то вроде этого (XSLT 1.0):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kTeamByName" match="Home|Away" use="."/>
<xsl:template match="/*">
<table border="1">
<tr>
<td>Team</td><td>W</td><td>D</td><td>L</td>
</tr>
<xsl:apply-templates select=
"(*/Home | */Away)
[generate-id()
=
generate-id(key('kTeamByName', .)[1])
]
">
<xsl:sort data-type="number" order="descending" select=
"count(key('kTeamByName', .)
[self::Home
and
../Home_Score > ../Away_Score
or
self::Away
and
../Away_Score > ../Home_Score
]
)
"/>
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="Home|Away">
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:value-of select=
"count(key('kTeamByName', .)
[self::Home
and
../Home_Score > ../Away_Score
or
self::Away
and
../Away_Score > ../Home_Score
]
)"/>
</td>
<td>
<xsl:value-of select=
"count(key('kTeamByName', .)
[../Home_Score = ../Away_Score]
)"/>
</td>
<td>
<xsl:value-of select=
"count(key('kTeamByName', .)
[self::Home
and
../Away_Score > ../Home_Score
or
self::Away
and
../Home_Score > ../Away_Score
]
)"/>
</td>
</tr>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
когда это преобразование применяется к предоставленному документу XML :
<Games>
<Game>
<Home>Team A</Home>
<Away>Team B</Away>
<Home_Score>20</Home_Score>
<Away_Score>15</Away_Score>
</Game>
<Game>
<Home>Team C</Home>
<Away>Team D</Away>
<Home_Score>12</Home_Score>
<Away_Score>18</Away_Score>
</Game>
<Game>
<Home>Team A</Home>
<Away>Team C</Away>
<Home_Score>8</Home_Score>
<Away_Score>8</Away_Score>
</Game>
<Game>
<Home>Team B</Home>
<Away>Team D</Away>
<Home_Score>6</Home_Score>
<Away_Score>14</Away_Score>
</Game>
<Game>
<Home>Team D</Home>
<Away>Team C</Away>
<Home_Score>9</Home_Score>
<Away_Score>11</Away_Score>
</Game>
<Game>
<Home>Team C</Home>
<Away>Team A</Away>
<Home_Score>13</Home_Score>
<Away_Score>13</Away_Score>
</Game>
</Games>
желаемый, правильный результат получается :
<table border="1">
<tr>
<td>Team</td>
<td>W</td>
<td>D</td>
<td>L</td>
</tr>
<tr>
<td>Team D</td>
<td>2</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>Team A</td>
<td>1</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td>Team C</td>
<td>1</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>Team B</td>
<td>0</td>
<td>0</td>
<td>2</td>
</tr>
</table>