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

 

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (2,250)