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
Super User

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,935)