XSL for-each/when problem

Hey,

Not sure if much XSL stuff goes on in here, but im currently having a problem and the debug information is as useless as a a chocolate fireguard.

Im currently just trying to do something simple…

Read in an XML file, style it with an XSL file, then display it in a div…
All works fine, but as soon as i try to put in sorting logic it just all falls apart and i dont have a clue why…



<xsl:param name="sort_type"/>

    
<xsl:template match="/">

<table cellspacing="0" cellpadding="0" border="0" >
  <tr>
    <th>Address 1</th>
    <th>Address 2</th>
  </tr>
<xsl:for-each select="people/person">
  <xsl:choose>
    <xsl:when test="contains($sort_type, 'address_1')">
      <xsl:sort select="address_1" order="descending" data-type="text" />        
    </xsl:when>
    <xsl:otherwise>
      <xsl:sort select="id" order="descending" data-type="number" />
    </xsl:otherwise>
  </xsl:choose>
  <tr>
    <td><xsl:value-of select="address_1" /></td>
    <td><xsl:value-of select="address_2" /></td>
  </tr>
</xsl:for-each>
</table> 

    </xsl:template>

There is also stuff for the stylesheet defines but i thought i would only bother showing the core part. Anyway as you can see i do the for-each, then sort it based on the $sort_type, the sort_type is set via javascript externally, but i know it works as if i display it via XSL without the sorting logic it displays the correct contents. The default XML contains people, which contains many persons, all having address 1,2 and an ID but i only want to display the addresses.

The error i keep getting basically says there is an exception when processing the XSL, if i take out the sorting logic it works fine, so am i doing something wrong, im basing most of my stuff from the w3schools and other various tutorials online…

ANY help would be great!