Re: [xsl] Conditional xsl:sort and leaving some items out of sorting

Subject: Re: [xsl] Conditional xsl:sort and leaving some items out of sorting
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 12 Jul 2006 11:44:30 +0100
> But this is illegal syntax, as xsl:sort cannot be a child of xsl:if. It 
> doesn't trigger an error either, by the way.
It should generate an error.

      <xsl:sort select="($name = 'generic' and position()) or 
twz:cell[1]" order="ascending" />

close but not quite;-) That is a boolean valued expression so you are
sorting the key values "true" and "false" which isn't what you want,
what you want is;

  <xsl:sort select="twz:cell[not($name = 'generic')][1]"/>

If $name = 'generic' then this selects the empty node set for each item,
so no sorting is done (or at least its sorted with an empty sort key,
which eis effectively the same thing) and if $name is not 'generic' it
selects the first cell child, and so that is used as the sort key.

  In addition, 
  I would like to ask how to extend the solution above to order the list 
  in such a way that all is ordered except items that have the value 
 "None" or "All". These should end up on the bottom of the list.

 
  <xsl:sort select="twz:cell[not($name = 'generic')][1][.='None', or .='All']"/>
  <xsl:sort select="twz:cell[not($name = 'generic')][1]"/>

the major sort key will have sort key  of "", "All" or "None" sorted in
that order, then the second  sort key will arrange the ones with "".

David

Current Thread