php - XPath 1.0 - Make selection based on value of text spread over multiple nodes -
<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 above xml xpath 1.0 query select <div>
s based on foobar
appearing within single <span>
or split across multiple consecutive <span>
s? want select first , third <div>
. second <div>
contains fobar
, not foobar
. in fourth <div>
<span>
s not consecutive. fifth <div>
has <img>
between <span>
s they're no longer consecutive , text of sixth foobarbaz
, not foobar
. seventh has correct text not within <span>
s.
i have tried using concat()
doesn't work because need know number of arguments first. also, saying concat(//*, //*)
equivalent concat(//*[1], //*[1])
, not want.
this within php have xpath 1.0.
you can try xpath :
/root/div[contains(normalize-space(.), 'foobar')]
notice .
returns concatenation of text nodes within current context node.
output in xpath tester :
element='<div> <p>this text</p> <p> <span>fo</span> <span>ob</span> <span>ar</span> </p> </div>' element='<div> <p>this text</p> <p> <span>fooba</span> <span>r</span> </p> </div>'
Comments
Post a Comment