I'm trying to write an Xpath Statement (1.0) that can read info from a 'search' node and perform a search using it.
I was making some nice progress, but stumbled across an issue where if an attribute (used for a value in the search) is empty or doesn't exist, it fails.
Code Edited to simplify Example:
So Here is my sample XML:
<xml>
<files>
<file name="foo" description="" rating="4"/>
<file name="food" description="" rating="4"/>
<file name="foobar" description="" rating="3"/>
<file name="bar" description="" rating="3"/>
<file name="barter" description="" rating="3"/>
<file name="barterer" description="" rating="2"/>
</files>
<searches>
<search id="1">
<exclude>
<file term="foo"/>
</exclude>
</search>
</searches>
</xml>
And working XPATH:
//files/file[
not(contains(@name, //search[@id='1']/exclude/file/@term))
]
It works as expected...
However if the an expected attribute is missing or empty it will fail to work. I think because: contains(@attrib, "") matches everything for some-reason, therefore a not() will always match nothing if the attribute is "" or not present.
For Example, if I alter the exclude fragment of XML to this it fails:
<exclude>
<file term=""/>
</exclude>
with this too:
<exclude></exclude>
Is there a way to Check for an empty value and not perform the select? or is there perhaps a better way of structuring the Logic. Bare in mind I cannot use Conditionals or the other functions in Xpath2.0.