Hello Chuck,
Maybe I will have time to look at your code later, but the first thing that came to mind was to use `group by`:
map:merge( for $pmidset at $i in $pmids group by $chunk as xs:integer := ($i idiv 100) return map:entry($chunk, $pmidset) )
This should give you the map you expect.
Best regards, Nico Verwer