Search code examples
xmlxsltxpathxpath-2.0xpathquery

xpath query conditional test comparing 2 numeric values


can someone explain to me why this condition return false in this following xpath query

xml

<?xml version="1.0" encoding="UTF-8"?>
<a>ha</a>

xpath query

count(//a) return 1.

but

test="(count(//a) > 0)" return false?

Thank you


Solution

  • In the query

    test="(count(//a) > 0)"
    

    test refers to a child element of the document node called "test". If there is no such element (which is the case here), then you are comparing an empty set to the string "count(//a) > 0". Comparing an empty set to anything returns false.