cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
acrespo
Regular Visitor

How to insert variable in power automate xpath expression

Hello,

 

Trying to replace "FacturaElectronica" in the expression bellow by a variable: variables('TipoDoc'). Tried to build the string with concat() but have not been able to make it work. 

 

xpath(xml(outputs('Obtener_contenido_de_XML_2')), 'string(/*[name()="FacturaElectronica"]/*[name()="Emisor"]/*[name()="Nombre"])')
 
Any suggestions? Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
v-litu-msft
Community Support
Community Support

Hi @acrespo,

 

You could do like this:

1. Store the Xpath into a Compose action;

string(/*[name()="@{variables('TipoDoc')}"]/*[name()="Emisor"]/*[name()="Nombre"])

2. Append the output of Compose into the second parameter of Xpath() function:

xpath(xml(outputs('Obtener_contenido_de_XML_2')), outputs('Compose_4'))

Screenshot 2021-03-01 112532.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
manuelstgomes
Super User II
Super User II

Hi @acrespo 

 

Try copying with the following structure:

@{variables('TipoDoc')}

 

Cheers
Manuel

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

acrespo
Regular Visitor

Thanks Manuel - 

 

This gives me an invalid expression and doesn't allow to save even (also without the @):

xpath(xml(outputs('Obtener_contenido_de_XML_2')), 'string(/*[name()=@{variables('TipoDoc')}]/*[name()="Emisor"]/*[name()="Nombre"])')

 

This is the closest I have gotten but somehow the xpath doesn't work, it just returns the concatenated string instead of the xml content: 

xpath(xml(outputs('Obtener_contenido_de_XML_2')), concat('''string(/*[name()=',variables('TipoDoc'),']/*[name()="Emisor"]/*[name()="Nombre"])'''))

 

Any other ideas I should try?

 

Thanks,

v-litu-msft
Community Support
Community Support

Hi @acrespo,

 

You could do like this:

1. Store the Xpath into a Compose action;

string(/*[name()="@{variables('TipoDoc')}"]/*[name()="Emisor"]/*[name()="Nombre"])

2. Append the output of Compose into the second parameter of Xpath() function:

xpath(xml(outputs('Obtener_contenido_de_XML_2')), outputs('Compose_4'))

Screenshot 2021-03-01 112532.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
User Groups Public Preview

Join us for our User Group Public Preview!

Power Automate User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Users online (27,737)