Thank's for your quick reply. I try to give you an example as I don't think my english is good enough to explain you otherwise:
No problem. The following query will exclusively return the request node without its descendants:
let $xml := <AAA> <BBB att1="bbb"> <CCC att1="ccc"/> <DDD att1="ddd"> <EEE att1="eee"/> </DDD> </BBB> </AAA>
let $result := $xml//DDD return element { node-name($result) } { $result/@*}
Several approaches exist to also include the ancestor nodes in the result. One of them is to use the "transform" expression (copy/modify) and delete the irrelevant nodes from the result:
copy $xml := <AAA> <BBB att1="bbb"> <CCC att1="ccc"/> <DDD att1="ddd"> <EEE att1="eee"/> </DDD> </BBB> </AAA> modify delete node $xml//DDD/node() return $xml
If gets more difficult if you want to omit any other following and preceding nodes. This one here is one possible solution:
copy $xml := <AAA> <BBB att1="bbb"> <CCC att1="ccc"/> <DDD att1="ddd"> <EEE att1="eee"/> </DDD> </BBB> </AAA> modify ( let $result := $xml//DDD return ( delete node $result/child::node(), delete node $result/preceding::node(), delete node $result/following::node() ) ) return $xml
As a conclusion.. XQuery is very powerful! You might need some initial time to get to know it, but I’d claim it’s worth the trouble.
Hope this helps, Christian