I’m attempting to create an xquery expression that will return selected nodes but will not return their children. This is probably best illustrated with an example. I have the following myNode node:
<myNode>
<myElements id="1">
<myElement key="one">aaa</myElement>
<myElement key="two" >bbb</myElement>
<myElement key="three">ccc</myElement>
</myElements>
<myElements id="2">
<myElement key="one">ddd</myElement>
<myElement key="two" >eee</myElement>
<myElement key="three">fff</myElement>
</myElements>
</myNode>
I am interested in returning the <myElements > nodes, but nothing lower. My desired return would look like the following:
<myNode>
<myElements id="1" />
<myElements id="2" />
</myNode>
or
<myNode>
<myElements id="1"></myElements>
<myElements id="2"></myElements>
</myNode>
I currently have a xpath expression that would look something like the following (simplified for this illustration), which as expected, is returning the myElement children:
$results/myNode/MyElements
Am I barking up the wrong tree? Is this even possible in XPath/XQuery?
Try this recursive algorithm..