I am quite new to XPath so bear with me. I have a XPath expression
'.//*[contains(.,"Obama")]/text()'
that gets me the text that contains “Obama”. However, I haven’t been able to figure out how to add
and [not(contains(., "Romney"))] to the expression without getting a syntax error. How is it done? Help much appriciated!
Use:
XSLT – based verification:
When this transformation is applied on the following XML document:
the XPath expression is evaluated and the selected node is copied to the output:
Do note:
is not always equivalent to:
Therefore, it is recommended the latter — not the former, as specified in the answer by @ChrisGerken.
Here is a concrete example:
Let’s have this XML document:
and these two XPath expressions:
and
The first expression selects:
However, the second expression selects:
And here is a complete XSLT – based verification:
When this transformation is applied on the above XML document, the two XPath expressions are evaluated and the results of these evaluations are copied to the output:
Explanation:
position()is a *context-sensitive` function and typically produces different results when used in the k-th and in the m-th predicate, where k != m