well the way i did it, and maybe not the way you are trying to do it, is to pass a param back to the xsl page identifying the local-name of the element you want to sort on.
given:
<tablexml>
<headers>
<column-header sort-node="name"/>
...
<column-header sort-node="address" />
</headers>
<data>
<row><name/><address/>...</row>
<row>...</row>
</data>
</tablexml>
your xsl will look like a bit like this:
...
<xsl:template match="row" ... >
<xsl

aram name="$mylocalname" />
...
<xsl:apply-template select="*">
<xsl:sort select="$mylocalname"/>
</xsl:apply-template>
</xsl:template>
...
and then you need to pass in the local-name of the node that relates to the column in the table to the xsl stylesheet in the onclick function of the <td> tag.
the part of the xsl that generates the table headers will look a bit like this:
<xsl:template match="column-header"... >
<tr>
<xsl:element name="td">
<xsl:attribute name="onclick">
<xsl:text>
document.location.href="./myscript.blah?sortname='
</xsl:text>
<xsl:value-of select="@sort-node"/>
<xsl:text>';"</xsl:text>
</xsl:attribute>
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:template>
.. and when you generate the page with "myscript.blah" pass the value "sortname" to the xsl stylesheet as a parameter, which should then sort the results of the data correctly.
ps i have not tested any of this, but feel free to ask if you have problems.
hope that helps.