Pseudocode would be something like:
let $myNode as node() := $node
for $subpath in tokenize($path,'/')
$myNode := $myNode/*[name()=$subpath] (: Here is the invalid line :)
I know there is a operator for this in xQuery 3.0, I am asking for xQuery 1.0.
There’s no XQuery 2.0, but what you want to do isn’t possible only with a FLWOR expression regardless of version. The set of current nodes would have to be updated between iterations, which isn’t how FLWOR expressions work.
That said, what you want to do is easily possible with a recursive function in XQuery 1.0:
You can call it with
local:path(document{ <x><y>foo</y><z/></x> }, tokenize("x/y", '/')).In XQuery 3.0 it’s even easier to do, without a new top-level function:
The function fn:fold-left(..) takes care of the recursion internally and you only have to specify how to modify the context set in each step.