0

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

3
  • 1
    "test="(count(//a) > 0)" return false" How did you arrive at this conclusion? Commented Jan 19, 2015 at 20:49
  • You are right. I think putting test="whatever" into xpath query editor will always return false Commented Jan 19, 2015 at 21:29
  • test="whatever" is not an XPath expression; it's an attribute of an XSLT instruction, e.g. <xsl:if test="count(//a) > 0">Yes</xsl:if>. Commented Jan 19, 2015 at 22:15

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe you don't need the "" marks.

From the free tool XPathBuilder:

enter image description here

http://www.bubasoft.net/product/xpath-builder/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.