In this xml, I want to match, the element containing ‘match’ (random2 element)
<root>
<random1>
<random2>match</random2>
<random3>nomatch</random3>
</random1>
</root>
ok, so far I have:
//[re:test(.,'match','i')] (with re in the proper namespace)
this returns random2, random1 and root… I would like to get only “random2”
any ideas?
Do you want to find elements that contain “match”, or that equal “match”?
This will find elements that have text nodes that equal ‘match’ (matches none of the elements because of leading and trailing whitespace in
random2):This will find all elements that have text nodes that equal “match”, after removing leading and trailing whitespace(matches
random2):This will find all elements that contain ‘match’ in the text node value (matches
random2andrandom3):This XPATH 2.0 solution uses the
matches()function and a regex pattern that looks for text nodes that contain ‘match’ and begin at the start of the string(i.e.^) or a word boundary (i.e.\W) and terminated by the end of the string (i.e.$) or a word boundary. The third parameterievaluates the regex pattern case-insensitive. (matchesrandom2)