Is there a way to do something like this?

declare function local:insert(
  $doc as node(), 
  $at-location as xpath(),  (: I know, there is no 'xpath' type, this is just for demo :)
  $what as node()*
) as node() {
  copy $c := $doc
  modify insert node $what into $at-location
  return $c
};

let $xml := <xml><body><p>This is a paragraph.</p></body></xml>
let $nd := <this><is><a>Test</a></is></this>
return local:insert($xml, xpath("/body"), $nd)

As I see it, it would need a dynamic xs:string => XPath expression conversion or a defer XPath expression, which both do not exist, for $at-location. I managed to do this, however:

declare function local:insert($doc, $at-location, $what) {
  let $update := ``[
  declare variable $doc external;
  declare variable $what external;
  declare variable $at-location external;  
copy $c := $doc
modify insert node $what into `{$at-location}`
return $c
]``
  return xquery:eval($update, map{
    'doc':$doc,
    'at-location':$at-location,
    '$what':$what
  })
};

let $xml := <xml><body><p>This is a paragraph.</p></body></xml>
let $node := <this><is><a>Test</a></is></this>
return local:insert($xml, "$c/body", $node)

Ideally (for me), there would be a 'defer' XPath expression, that starts its life as a string (when passed) and then unfolds upon call. Or a type (or function) fn:xpath(), that behaves that way.

Or am I just blind and don't see the obvious, and there is a simpler solution?

-- 
Minden jót, all the best, Alles Gute,
Andreas Mixich