I am trying to develop a DB2 embedded XML subroutine whose purpose is "Given document A, a unique element named B of unknown depth within A, please insert element C as last into B" making use of FLWOR. My procedure works OK, as long as 'B' is not the root tag.
Here is the dynamic statement:
XQuery copy $new := %s modify do insert %s as last into $new//%s return $new
In which the first %s is the old document, the second %s is the element to be inserted, and the third %s is the child element that should receive a new element within.
It works fine unless child == root. It traces back to the double-slash producing no results if child == root. But shouldn't this work too?
To put it another way, the first two if these produces one result each, but the third does not. In the Path evaluator of Altova XMLSpy produces one result.
XQuery <a><b><c/></b></a>//c (works, one result)
XQuery <a><b><c/></b></a>//b (works, one result)
XQuery <a><b><c/></b></a>//a (no result, but shouldn't it work?)