XPath to select array of nodes satisfying a child property with Logic Apps

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

The final query expression we will be decomposing today is this:


xpath(xml(variables('count')), '/*[local-name()="lists"]/*[local-name()="list"]/*[local-name()="name" and text()="*Billable"]/..')



This is the XPath function (https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#xpath).

We assume there is a count string typed variable containing the XML payload to query into. The variables function looks-up that variable (https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#variables).

The XML function (https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#xml) parses that string input to an XML document which the XPath function expects as first input.


Then comes the XPath itself


/*[local-name()="lists"]/*[local-name()="list"]/*[local-name()="name" and text()="*Billable"]/..








allows to select all 'lists' named elements at root level without consideration for namespace. Beware many online XPath test tools will ignore the input XML document namespace, while .NET, and Logic Apps XPath function built with .NET, honor the namespace. So for a node to match with just 




it needs to be 




with no namespace assigned. Beware children nodes inherit default namespaces assign by their parents (








/*[local-name()="name" and text()="*Billable"]


lets you select all the name nodes where the name value is '*Billable'. It is typical to want to select elements from an XML array which have specific value for a child node or attribute. This demonstrate selecting the name nodes equal to *Billable.






lets you go back to the parent node of the name node, so you are able to list all the 'list' elements which satisfied the condition on their leave nodes (has a name element of value *Billable).

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.