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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Does xpath support sib...
Power Automate
Answered

Does xpath support siblings?

(0) ShareShare
ReportReport
Posted on by 2
<Transaction>
    <DataElement>
        <BusinessObjectName i:nil="true" />
        <Keys xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <a:string>invoice_no</a:string>
        </Keys>
        <Name>TABPAGE_17.invoice</Name>
        <Rows>
            <Row>
                <Edits>
                    <Edit>
                        <IgnoreIfEmpty>false</IgnoreIfEmpty>
                        <Name>invoice_no</Name>
                        <Value>1423071</Value>
                    </Edit>
                    <Edit>
                        <IgnoreIfEmpty>false</IgnoreIfEmpty>
                        <Name>receivable_amt</Name>
                        <Value>103.37</Value>
                    </Edit>
                </Edits>
                <RelativeDateEdits />
            </Row>
        </Rows>
        <Type>List</Type>
    </DataElement>
    <DataElement>
        <BusinessObjectName i:nil="true" />
        <Keys xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <a:string>invoice_no</a:string>
        </Keys>
        <Name>TABPAGE_17.invoice</Name>
        <Rows>
            <Row>
                <Edits>
                    <Edit>
                        <IgnoreIfEmpty>false</IgnoreIfEmpty>
                        <Name>invoice_no</Name>
                        <Value>1428090</Value>
                    </Edit>
                    <Edit>
                        <IgnoreIfEmpty>false</IgnoreIfEmpty>
                        <Name>receivable_amt</Name>
                        <Value>136.74</Value>
                    </Edit>
                </Edits>
                <RelativeDateEdits />
            </Row>
        </Rows>
        <Type>List</Type>
    </DataElement>
</Transaction>
 
 
I am trying to get the following xpath statement to work based on the above XML sample using sliblings, but cannot get this to work.
 
xpath(outputs('Failed_Transaction_Result'),'string(//Name[contains(text(),"invoice_no")]//following-sibling::Value')
 
 
Can anyone confirm whether this is supported?
I would like to get all of the <Value> if the <Name> = "invoice_no".
 
Ideally the results would look like this:
1423071, 1428090
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Mark Nanneman Profile Picture
    991 Moderator on at
    Hello, I was able to get a result like what you want, but I had to clean up the XML first.

    Power Automate doesn't seem to like the lines with "i:nil" in them--it reports an error when trying to convert the string XML to actual XML on the i character.  I don't know why this, perhaps someone else with more knowledge of XML could tell us.

    To get it to work and prove the principle of using Xpath to get what you want, I just deleted both of these instances:
     
    <BusinessObjectName i:nil="true" />
     
    from your XML.  Obviously, you'll probably want to find a better solution to deal with this.
     
     

    Step One: I Put your XML in a compose (and removed the i:nil lines)

     

    Step Two: I converted your XML string to XML

    I just put xml() around the output of the first compose

     

    Step Three: I use Xpath to get an array of failed Invoice Numbers

    I used this expression.  You can try using the "Create an expression with Copilot" AI assitant to guide you in making xpath formulas.  I also tested ChatGPT and it gave me the correct format for power automate as well.

    Here's Microsoft's documentation on xpath for the full details:
     

     
    xpath(
         outputs('Failed_Transaction_Result'),
         '//Edit[Name="invoice_no"]/Value/text()'
    )

    And used a join to make a string of the invoice numbers:


    Testing

    Here the values are returned as an array

    Here I join them into one string.



    If this helped you, please click "Does this answer your question" and give it a like to help others in the community (+ close the ticket)!

    Power Platform Developer | LinkedIn: Mark Nanneman | Blog: Power Stuff  | YouTube: Mark's Power Stuff  |
  • Verified answer
    Pstork1 Profile Picture
    69,037 Most Valuable Professional on at
    I did a little test and got this to work, but there was an issue with your raw XML code.  The line was invalid because i: is not declared as a prefix.  After removing the two lines that had that in it the following code worked for me.
     
    xpath(xml(outputs('Compose')),'//Edit/Name[text()="invoice_no"]/following-sibling::Value/text()')
    This returned the following array
     
    [
      "1423071",
      "1428090"
    ]

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 286

#2
David_MA Profile Picture

David_MA 256 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 225 Most Valuable Professional

Last 30 days Overall leaderboard