cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Spinhalyard
Frequent Visitor

Strange results (actually no results) from XPath expression when used in Power Automate.

This is my first post in the community so I'm going to start with a quirky one.

Use Case:

A document has been approved for publishing and copied to a specific directory, i.e., ...\whatever\published.

I want to automatically copy all text in the document that has a style of "Quote" into a SharePoint List named "Snippets" to be used elsewhere.

Proposed Solution:

The flow is triggered by the file action

  1. replaces the .docx extension with .zip (I'll work on this later)
  2. extracts the .xml files from the archive (done)
  3. selects the correct .xml document (done)
  4. removes garbage from the file (done)
  5. queries the document (XPath) for all text with the Style "Quote" (almost works but something is off)
  6. Outputs that content to a SharePoint list (no worries)

I have successfully extracted the actual text "t" from the document, but when I try to use an expression to isolate only the text formatted as a quote, the flow fails to return results.

 

Here is the simple expression I used to test the theory.  It works fine but returns all text:  xpath(xml(outputs('Remove_"w:"_garbage')?['body']), '//*[name()="t"]/text()').

 

When I try to be more prescriptive: xpath(xml(outputs('Remove_"w:"_garbage')), 'pStyle[@val="Quote"]/ancestor::p/r/t/text()'), it returns nothing, even though it works fine when I take the output from "Remove "w:" garbage" and test it in Visual Studio Code.

 

Since it works outside of Power Automate, I assumed there was something quirky about using XPath in PA.  Really hoping for a "Well duh!" fix to this from the group.  The documentation I found wasn't very helpful.

 

Thanks in advance!

 

Spinhalyard_0-1627084205796.png

 

Spinhalyard_1-1627071136885.png

vs.

 

Spinhalyard_1-1627084384606.png

Works fine outside of PA

Spinhalyard_2-1627085308930.png

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Spinhalyard
Frequent Visitor

Doh!  It was a "Well Duh!" moment.  I just noticed I forgot to add the Context Node when bringing it over from my test environment.  Working now!

 

Spinhalyard_0-1627087124758.png

 

View solution in original post

1 REPLY 1
Spinhalyard
Frequent Visitor

Doh!  It was a "Well Duh!" moment.  I just noticed I forgot to add the Context Node when bringing it over from my test environment.  Working now!

 

Spinhalyard_0-1627087124758.png

 

View solution in original post

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,314)