The evaluated query has its own query context. The only variables available inside are those passed in the bindings. If you want access to a map variable you must pass it in e.g.
declare %restxq:path('/test2') %restxq:GETfunction test:test2(){ let $map := map{ "map":map{ "greeting" : "hello","who": "world"} } return test:render('view2.xq', $map) };