August
August

Reputation: 487

Possible to define an xpath expression that selects <p> elements with hyphenated text but no child HTML tags?

Is it possible to define an xpath expression that selects all <p></p> elements that contain a hyphen in the text but no child html tags.

In other words, this would be selected by the xpath expression:

<p>Wednesday - Chess at Higgins Stadium</p>

But this would be excluded because of the child <b> tags:

<p><b>Wednesday</b> - Chess at Higgins Stadium</p> 

And this would be excluded because of the child <br/> tag:

<p><br/>Wednesday - Chess at Higgins Stadium</p> 

Upvotes: 0

Views: 672

Answers (1)

user357812
user357812

Reputation:

This XPath expression selects all p elements having only one node child been a text node containing - character:

//p[not(node()[2])][contains(text(),'-')]

or

//p[count(node())=1][contains(text(),'-')]

Upvotes: 3

Related Questions