>the debug information is as useless as a a chocolate fireguard.
Perhaps you need a better development environment? Might I guess that you are trying to develop and test your code by running it in the browser? That's the worst possible route you could choose.
This is what Saxon says about your code:
Error at xsl:sort on line 18 column 74 of file:/c:/temp/test.xsl:
XTSE0010: An xsl:when element must not contain an xsl:sort element
Error at xsl:sort on line 21 column 69 of file:/c:/temp/test.xsl:
XTSE0010: An xsl:otherwise element must not contain an xsl:sort element
Failed to compile stylesheet. 2 errors detected.
Which is about as clear a statement of your error as I could come up with.
In XSLT 2.0 you can write a conditional expression (if-then-else) inside the xsl:sort select="". If you're stuck with XSLT 1.0 then one way of solving the problem is to have two sort keys, one of which has no effect:
<xsl:for-each select="people/person">
<xsl:sort select="address_1[contains($sort_type, 'address_1')]"
order="descending" data-type="text" />
<xsl:sort select="id[not(contains($sort_type, 'address_1'))]"
order="descending" data-type="number" />
Another is to compute a variable $sort_key outside the for-each, with value "address_1" or "id", and then use <xsl:sort select="*[name()=$sort_key]".
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference