I've just been working on a problem with an XPath expression in an orchestration and thought its strangeness warranted a Blog - just to see if anyone else had come across it and to make other people aware of it really.
What I am trying to do is check the count of a certain child element in a message for zero and not to perform a send operation if it is zero. Sounds simple and here is the Boolean expression from my decide shape:
xpath(msg, "count(/*[local-name()='root']/*[local-name()='child'])")) != "0"
(Note I've abbreviated the XPath here before anyone says it's wrong - it is definitely right.)
That expression always evaluated to true. I even dumped out the result of the XPath as debug information to check and it was 0.
Confused, I changed the expression as follows:
System.Convert.ToInt32(xpath(msg, "count(/*[local-name()='root']/*[local-name()='child'])"))) != 0
Basically convert the XPath result to an integer and check its value against numeric zero rather than a string of zero. This works perfectly.
If anyone can explain this strange behaviour I'd appreciate it. If not at least its one for everyone else to be aware of.
Oh and I do have SP1 installed before anyone asks.