arnaudbey
arnaudbey

Reputation: 900

Find nodes containing string split over 2 tags

is there a way to get nodes containing a specific string which is split over 2 tags. I tried this but it doesn't work. I can't manage to ignore foreign tag.

$crawler->filterXPath('//p/text()[contains(., "caractère a priori")]');
<p>leur caractère <foreign xml:lang="lat">a priori</foreign>, soit..</p>

Thanks a lot !

Upvotes: 1

Views: 84

Answers (1)

Dan Gardner
Dan Gardner

Reputation: 1279

The below XPath should work for you, it will return only <p> nodes which contain the text specified in the contains statement. I've expanded the example a bit, for me to test, and included a fiddle here.

XPath:

div/p[contains(., 'caractère a priori')]

Input

<div>
    <p>leur caractère <foreign xml:lang="lat">a priori</foreign>, soit..</p>
    <p>leur poisson <foreign xml:lang="lat">a priori</foreign>, soit..</p>
</div>

Output

<p>leur caractère <foreign xml:lang="lat">a priori</foreign>, soit..</p>

Hopefully that give you enough to go on!

Upvotes: 1

Related Questions