I haven't tried this for your example bit normally you put the variable declaration around the test:
Code:
<xsl:variable name="maxValue">
<xsl:for-each select="item">
<xsl:sort data-type="number" order="ascending" select="@value"/>
<xsl:if test="position()=1">
<xsl:value-of select="@value"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
Then use $maxValue to produce your other variables.
--
Joe