Need to see how you're calling this: the calling template in the stylesheet, and the source document.
You don't say what value you're trying to return when the name is found.
This code looks very peculiar:
<xsl:when test="$list[1]=$name">
number($returnValue)+1
</xsl:when>
Did you mean to write
<xsl:when test="$list[1]=$name">
<xsl:value-of select="number($returnValue)+1"/>
</xsl:when>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference