Reputation:
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!
Upvotes: 2
Views: 9582
Reputation: 338376
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
Upvotes: 1
Reputation: 271
/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.
Upvotes: 3
Reputation: 11287
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.
Upvotes: 1