xquery - How to choose certain nodes/words from a string -


i have code

for $sea in distinct-values (doc("mondial.xml")//island/tokenize(@sea,"\s")) let $count := count(doc("mondial.xml")//island[@sea = $sea]/tokenize(@sea,"\s")) let $seacount := concat($sea," ",$count) return $seacount 

which returns me

"sea-arcticocean 3 sea-greenlandsea 0 sea-norwegiansea 1 sea-barentssea 0

sea-atlantic 53 sea-labradorsea 0 ..." , on.

the number can see $count , sea-xxx part variable $sea. i'm stuck on somehow choosing $sea has max value of $count of of counts , displaying sea-name. i've tried things adding $max variable to:

 $sea in distinct-values (doc("mondial.xml")//island/tokenize(@sea,"\s")) let $count := count(doc("mondial.xml")//island[@sea = $sea]/tokenize(@sea,"\s")) let $seacount := concat($sea," ",$count) $max := concat($sea," ",max($count)) return $max 

also tried adding order $count (descending) statement , returning first node:

for $sea in distinct-values (doc("mondial.xml")//island/tokenize(@sea,"\s")) let $count := count(doc("mondial.xml")//island[@sea = $sea]/tokenize(@sea,"\s")) let $seacount := concat($sea," ",$count) order $count descending return $seacount[1] 

am approaching wrong way or ?

that return first node of result sequence for each iteration. in case, $seacount squence of 1 string, selecting equivalent of ('sea-value count')[1], singleton string value. select 1 overall, wrap whole query in parens create sequence of values iterations, , select first of those:

(for $sea in distinct-values (doc("mondial.xml")//island/tokenize(@sea,"\s")) let $count := count(doc("mondial.xml")//island[@sea = $sea]/tokenize(@sea,"\s")) let $seacount := concat($sea," ",$count) order $count descending return $seacount)[1] 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -