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开发者_JAVA百科, 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>
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(),'-')]
精彩评论