XPath to select array of nodes satisfying a child property with Logic Apps
Published Jun 18 2020 11:59 AM 9,643 Views

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#x...).

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#v...).

The XML function (https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#x...) 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).

Version history
Last update:
‎Jun 18 2020 11:59 AM
Updated by: