This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using variables in xsl:sort select attribute
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Using variables in xsl:sort select attribute
- From: Adam Turoff <ziggy at panix dot com>
- Date: Thu, 24 May 2001 12:35:41 -0400
- References: <F1C1C54946A4D411A34300D0B73EC96DB3703C@inftormail02.724.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
On Thu, May 24, 2001 at 12:01:50PM -0400, Mike McGraw wrote:
> <xsl:template match="customerList">
> <xsl:variable name="sortby" select="@sortby">
>
> <xsl:for-each select="person">
> <xsl:sort select="$sortby"/>
> <tr>
> <td><xsl:value-of select="name" /></td>
> <td><xsl:value-of select="age" /></td>
> </tr>
> </xsl:for-each>
>
> </xsl:template>
>
> However, this doesn't work. The parser ignores the sort instruction. Am I
> permitted to use a variable as the argument for the select attribute of the
> sort?
It looks like select="$sortby" is a constant expression, so the results
are in their original order.
Try this instead (yes, it's ugly, but it sorts):
<xsl:for-each select="person/*[name() = $sortby]">
<xsl:sort select="."/>
<tr>
<td><xsl:value-of select="../name" /></td>
<td><xsl:value-of select="../age" /></td>
</tr>
</xsl:for-each>
Z.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list