Considering the following XML
<xml>
<tag/>
<tag version="2.1"/>
</xml>
I want an XPath 1.0 expression that returns <tag version="2.1"/> if I search for version 2.1, and <tag/> if I search for version 2.2.
So far, I've tried
/xml/tag[@version = '%version%' or not(@version)]
where %version% is a string that can be either 2.1 or 2.2, but if %version% is 2.1, it returns both nodes.
2.1returns both, because in your xpath you door not(@version)and that will result in the tag without the attribute. So it does not matter what you pass into%version%, because always<tag/>will be returned because of theorstatement... What you are trying to achieve is not possible in one XPath statement. Should be solved in code