I am writing below code :-
xquery version "1.0-ml";
declare variable $hosts := xdmp:host-name(xdmp:group-hosts(xdmp:group()));
let $map := map:map()
let $i := 1
for $h in $hosts
let $key := map:put($map, "$i", $h)
return
for $x in map:keys($map)
order by $x return
map:get($map, $x)
The above code returns me 4 hosts, host1.com, host2.com and host3.com I want to write the above code in such way that if I pass 1 it should return me host1.com or if i pass 3 it should return host3.com. how to achieve that?
If you only need the host name, all you need to do is:
Where
$indexwould be the argument that you provide. You can put that into a library module by declaring a function:See https://docs.marklogic.com/guide/app-dev/import_modules#id_26329 for more information about XQuery modules.