I have the following paths:
- /my:company/ns1:Audit/ns1:Visit/ns1:customField10
- /my:company/ns1:Audit/ns1:Visit/ns1:accountNumber
I want to select ns1:customField10 if it is not empty, otherwise I want to return ns1:accountNumber.
I tried the following:
xml.SelectSingleNode(
"(/my:cobius/ns1:Audit/ns1:Visit/ns1:customField10 |
/my:cobius/ns1:Audit/ns1:Visit/ns1:accountNumber)", ns)
But it is always returning accountNumber. I tried flipping the order of customField10 and accountNumber, but no joy. It still returns accountNumber.
How can I do the equivalent of the coalesce operator in XPath?
Update:
Here's the final code:
xml.SelectSingleNode(
"(/my:company/ns1:Audit/ns1:Visit/ns1:customField10[normalize-space()] |
/my:company/ns1:Audit/ns1:Visit/ns1:accountNumber[not(normalize-space(../ns1:customField10))])", ns)
xml.SelectSingleNode()
for both nodes and a normalif ...
after that?(node1, node2)[1]
in XPath 2.0, but only because XPath 2.0 is sequence-order-oriented. In contrast, XPath 1.0 is document-order-oriented (and it does not have a comma operator) so this will not work there.