Reputation: 84
I have this weird one-off that I need to do with xpath and I don't even know if it's possible. So far, I haven't found a way.
<things>
<stuff>here are some things <yep>blue</yep> and here are some more things</stuff>
</things>
Basically, I want to be able to get the text of "stuff" and all its children as if they are text as well. For example I want to get this:
here are some things <yep>blue</yep> and here are some more things
Upvotes: 1
Views: 51
Reputation: 29042
You can achieve this with the following XPath-2.0 expression:
for $p in /things/stuff/node() return if ($p instance of element()) then concat('<',$p/name(),'>',$p,'</',$p/name(),'>') else $p
But this is not a recursive solution, so it works only for the first level of elements.
Upvotes: 4