Using XPATH, how do I select multiple elements while retaining the path
Question
Assuming I have a XML like so:
<a>
<b>
<i>data</i>
<ii>data</ii>
<iii>data</iii>
</b>
<b>
<i>data<i>
<ii>data<ii>
<iii>data</iii>
</b>
</a>
Using XPath, how would I select the above XML to create a structure like so:
<b>
<i>data</i>
<ii>data</ii>
</b>
<b>
<i>data<i>
<ii>data<ii>
</b>
In this scenario I'm only interested in i and ii and, but want to retain the outer element. I also cannot use XSLT, only XPATH statements.
Thanks!
Solution
Maybe I'm wrong, but I thought XPATH only selects sequences of "nodes", in its own abstract model. I would be lost without XSLT here.
OTHER TIPS
/a/*/i/..|/a/*/ii/..
"From a, select all children, then select all "i" elements, then select the parent, OR from a select all children then select all "ii" elements, then select the parent.
To select all nodes and including their parent, outer nodes:
/a[i or ii]|/a/i|/a/ii|/b[i or ii]|/b/i|/b/ii
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow