Gareth
Gareth

Reputation: 59

XPath in a logic app to extract a value based on its type

I am using a logic app to dissect and reconstruct an inbound XML. The problem that I am having is that a portion of the XML is not always in the same order with the same amount of subsections. So I am wondering if it was possible to return the value based on the type? I.e in this example I want to return the value 2 where 2 is not always the second context.

 <ContextCollection>
  <Context>
    <Type>test1</Type>
    <Value>1</Value>
  </Context>
  <Context>
    <Type>test2</Type>
    <Value>2</Value>
  </Context>
  <Context>
    <Type>test3</Type>
    <Value>3</Value>
  </Context>

I have successfully used the following expression xpath(xml(variables('XMLStripNameSpace')),'string(/*[name()="ContextCollection"]/*[name()="Context"][2]/*[name()="Value"])')

but this obviously does not work when the test2 is the third Context.

Upvotes: 1

Views: 1540

Answers (1)

kjhughes
kjhughes

Reputation: 111621

This XPath,

//Context[Type = "test2"]/Value

will select all Value element children of Context elements of Type test2.

Upvotes: 2

Related Questions