xsl-list
[Top] [All Lists]

[xsl] Sort List of Maps By Key Value

2018-09-29 12:57:41
Using XPath 3 maps:

I have a list of maps where all the maps have a key on whose value I want to 
sort the list of maps.

Brute force I can do:

let $sortedKeys := $maps ! map:get(., 'sortonme') => sort()
for $key in $sortedKeys
      let $key := .
      let $map := $maps ! if (map:get(., 'sortonme') eq $key) then . else ()
      return func:operate-on-map($map)

But this seems unnecessarily brutish.

I'm still trying to get my head around how to use the "?" operator as well as 
functional mappings and whatnot.

So is there a more compact or clearer way to order a set of maps based on an 
order applied to the values of a given entry that exists in each map?

Thanks,

Eliot

--
Eliot Kimber
http://contrext.com
 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>