Share via

Logic App Xpath using dynamic values

Bryan Mangabang 1 Reputation point
2021-11-15T02:32:57.44+00:00

I am trying to get the specific xpath value from an HTTP response. I need to get

/UniversalResponse/Data/UniversalShipment/Shipment/DataContext/DataSourceCollection/DataSource/Key where
/UniversalResponse/Data/UniversalShipment/Shipment/DataContext/DataSourceCollection/DataSource/Type = "ForwardingShipment"

Sample HTTP response where I need to get the value:

<UniversalResponse>
 <Data>
  <UniversalShipment>
   <Shipment>
    <DataContext>
     <DataSourceCollection>
   <DataSource>
    <Type>ForwardingShipment</Type>
    <Key>A0008951</Key>
   </DataSource>
  </DataSourceCollection>

If I hardcode "ForwardingShipment" in the xpath, I could easily get the value in "Key":

xpath(xml(outputs('Remove_First_Line_In_Universal_Response')),'string(/*[local-name()="UniversalResponse"]/*[local-name()="Data"]/*[local-name()="UniversalShipment"]/*[local-name()="Shipment"]/*[local-name()="DataContext"]/*[local-name()="DataSourceCollection"]/*[local-name()="DataSource"][*[local-name()="Type"]="ForwardingShipment"]/*[local-name()="Key"])')

But the problem is, field "Type" could be any value that will be given from an input. Whenever I replace the type with a compose action ex:

[*[local-name()="Type"]="',outputs('Compose_Type'),'"]

Where "Compose_Type" is just a place value holder for whatever value is in the input, it either says invalid xpath expression or it just literally displays the code as it is:

xpath(xml(outputs('Remove_First_Line_In_Universal_Response')),'string(/*[local-name()="UniversalResponse"]/*[local-name()="Data"]/*[local-name()="UniversalShipment"]/*[local-name()="Shipment"]/*[local-name()="DataContext"]/*[local-name()="DataSourceCollection"]/*[local-name()="DataSource"][*[local-name()="Type"]="ForwardingShipment"]/*[local-name()="Key"])')

Where "ForwardingShipment" is already referenced from a compose action. How should I be able to make the dynamic value work for field "Type"?

Azure Logic Apps
Azure Logic Apps

An Azure service that automates the access and use of data across clouds without writing code.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.