RE: [xsl] XSL:SORT with Variable in 'select'

Subject: RE: [xsl] XSL:SORT with Variable in 'select'
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 15 Mar 2001 16:04:10 -0000
> I'm fairly new to XSLT and am not sure if the behavior I'm
> seeing (or lack
> thereof) is expected/desired.  Basically, I have set an attribute
> 'SortOrder' in my XML's root node (<Root>) equal to the name of the
> attribute on the <User> element that I want to sort the list
> of users by
> (see XML below):

This is a very common FAQ. For each node in the set you are sorting, the
value of the sort key is the string "@Name". There's no way the system can
know that this string is actually an XPath expression that it's supposed to
evaluate.

There's no way in standard XSLT of supplying XPath expressions in strings,
or reading them from the source document. Several products have an
evaluate() extension function to do this. Otherwise, for simple cases, use
select="*[name()=$sort-key]" if it's an element, or
select="@*[name()=$sort-key]" for an attribute.

Mike Kay
Software AG
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread