Я бы использовал следующий двухпроходный подход :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
<xsl:output omit-xml-declaration="yes"/>
<xsl:variable name="vrtfPass1">
<xsl:apply-templates select="/*" mode="getScore"/>
</xsl:variable>
<xsl:variable name="vPass1" select="ext:node-set($vrtfPass1)/*"/>
<xsl:variable name="vAverage" select=
"sum($vPass1//position/@score) div count($vPass1//position)"/>
<xsl:template match="node()|@*" name="identity" mode="getScore">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="getScore"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="$vPass1"/>
</xsl:template>
<xsl:template match="position" mode="getScore">
<position score="{(number + another)*count}">
<xsl:apply-templates mode="getScore"/>
</position>
</xsl:template>
<xsl:template match="position">
<xsl:if test="not(@score > $vAverage)">
<position>
<xsl:apply-templates mode="getScore"/>
</position>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
при применении к предоставленному документу XML :
<root>
<element>
<position>
<number>1</number>
<another>2</another>
<count>3</count>
</position>
<position>
<number>3</number>
<another>1</another>
<count>5</count>
</position>
<element>
<position>
<number>3</number>
<another>3</another>
<count>5</count>
</position>
<position>
<number>3</number>
<another>6</another>
<count>5</count>
</position>
<element>
<position>
<number>3</number>
<another>3</another>
<count>5</count>
</position>
<position>
<number>3</number>
<another>7</another>
<count>5</count>
</position>
<element>
<position>
<number>33</number>
<another>4</another>
<count>5</count>
</position>
<position>
<number>34</number>
<another>3</another>
<count>5</count>
</position>
</element>
</element>
</element>
</element>
<element>
<position>
<number>5</number>
<another>1</another>
<count>2</count>
</position>
<position>
<number>3</number>
<another>3</another>
<count>9</count>
</position>
<element>
<position>
<number>5</number>
<another>3</another>
<count>2</count>
</position>
<position>
<number>3</number>
<another>3</another>
<count>5</count>
</position>
</element>
</element>
</root>
желаемый, правильный результат получается :
<root>
<element>
<position>
<number>1</number>
<another>2</another>
<count>3</count>
</position>
<position>
<number>3</number>
<another>1</another>
<count>5</count>
</position>
<element>
<position>
<number>3</number>
<another>3</another>
<count>5</count>
</position>
<position>
<number>3</number>
<another>6</another>
<count>5</count>
</position>
<element>
<position>
<number>3</number>
<another>3</another>
<count>5</count>
</position>
<position>
<number>3</number>
<another>7</another>
<count>5</count>
</position>
<element>
</element>
</element>
</element>
</element>
<element>
<position>
<number>5</number>
<another>1</another>
<count>2</count>
</position>
<position>
<number>3</number>
<another>3</another>
<count>9</count>
</position>
<element>
<position>
<number>5</number>
<another>3</another>
<count>2</count>
</position>
<position>
<number>3</number>
<another>3</another>
<count>5</count>
</position>
</element>
</element>
</root>