html - XPath for two different tags (either one) that contain a specific word? -


i need xpath can find either <a> tag, or <option> tag, each 1 containing "something".

so xpath able match either

<a attributes='value'>something</a> 

or

<option attributes="value">something</option> 

i tried this:

$x("//*[local-name()='a' contains(.,'something') or local-name()='option' contains(.,'something')]") 

i tried this:

$x("//*[local-name(contains(.,'something'))='a' or local-name(contains(.,'something'))='option']") 

but neither of them work. in first one, can exclude contains() , finds tags, need able search tags containing specified "something" text.

you should post input xml.

let's it's this:

<r>   <a>xxx something</a>   <a>yyy nothing</a>   <option>something xxx</option>   <option>nothing xxx</option> </r> 

(1) (if you're trying ignore namespaces):

//*[(local-name() = 'a' or local-name() = 'option')][contains(., 'something')] 

(2) or (if there no namespaces) [credit: earlier @alecxe post]:

//*[self::option or self::a][contains(., "something")] 

(3) or (if using xpath 2.0, again without namespaces):

//(a|option)[contains(., 'something')] 

will select

<a>xxx something</a> <option>something xxx</option> 

Popular posts from this blog