[XQZone General] trick for dynamically setting a sort to ascending/descending

Travis Raybold travis at raybold.com
Mon Nov 28 17:36:01 PST 2005


in case this helps anyone... i found a cute little trick for sorting 
ascending and descending conditionally...

just sort by two values, the first one being the actual value if the 
order type is ascending and 1 otherwise (to ensure it doesn't do any 
actual sorting) and the second being a descending sort of the value if 
the sort type is descending, and 1 otherwise.

let $orderBy := "name"
let $orderDirection := "descending"
for $i in $nodes
  if ($orderDirection = "ascending") then $i/*[name()=$orderBy]  else 1,
  if ($orderDirection = "descending") then $i/*[name()=$orderBy] else 1 
descending
  return $i

--travis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3174 bytes
Desc: S/MIME Cryptographic Signature
Url : http://xqzone.marklogic.com/pipermail/general/attachments/20051128/41cb34c1/smime.bin


More information about the General mailing list