<root>
<div>
<p>this text</p>
<p><span>fo</span><span>ob</span><span>ar</span></p>
</div>
<div>
<p>this text</p>
<p><span>fo</span><span>b</span><span>ar</span></p>
</div>
<div>
<p>this text</p>
<p><span>fooba</span><span>r</span></p>
</div>
<div>
<p><span>foo</span>this text<span>bar</span></p>
</div>
<div>
<p><span>foo</span><img/><span>bar</span></p>
</div>
<div>
<p><span>foo</span><span>bar</span><span>baz</span></p>
</div>
<div>
<p>foobar</p>
</div>
</root>
Given the above XML what XPath 1.0 query would select the <div>
s based on foobar
appearing within a single <span>
or split across multiple consecutive <span>
s?
- I only want to select the first and third
<div>
. - The second
<div>
containsfobar
, notfoobar
. - In the fourth
<div>
the<span>
s are not consecutive. - The fifth
<div>
has an<img>
between the<span>
s so they're no longer consecutive. - The text of the sixth is
foobarbaz
, notfoobar
. - The seventh has the correct text but not within
<span>
s.
I have tried using concat()
but that doesn't work because I need to know the number of arguments first. Also, saying concat(//*, //*)
is equivalent to concat(//*[1], //*[1])
, which is not what I want.
This is within PHP so I only have XPath 1.0.
You can try this XPath :
Notice that
.
returns concatenation of all text nodes within current context node.output in xpath tester :