web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : HSp3YMwggq+VC9rC3lUKgd
Power Automate - Building Flows
Answered

How to insert variable in power automate xpath expression

Like (0) ShareShare
ReportReport
Posted on 26 Feb 2021 17:03:53 by 10

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
I have the same question (0)
  • manuelstgomes Profile Picture
    6,625 on 26 Feb 2021 at 17:35:56
    Re: How to insert variable in power automate xpath expression

    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 Profile Picture
    10 on 26 Feb 2021 at 19:05:28
    Re: How to insert variable in power automate xpath expression

    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,

  • Verified answer
    v-litu-msft Profile Picture
    on 01 Mar 2021 at 03:28:36
    Re: How to insert variable in power automate xpath expression

    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.

  • darkramuh Profile Picture
    11 on 09 Jan 2023 at 15:49:26
    Re: How to insert variable in power automate xpath expression

    If you using a lot of Xpath expressions in one action and don't want to create for each separate "Compose" action as per previous answer, You also can use "concat"

     

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 655 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 371 Moderator

#3
chiaraalina Profile Picture

chiaraalina 276

Last 30 days Overall leaderboard
Loading complete