Using concat of data in an XPath expression returns an error

Thomas Johnson 66 Reputation points
2022-02-08T21:24:05.62+00:00

The syntax I’m using is a valid Xpath expression, but Logic Apps is returning an error. Using concat() inside of Xpath expression returns the following error: ... The template language function 'xpath' parameters are invalid: the 'xpath' parameter must ne a supported. well formed XPath expression. ...

I validated my XPath on several online XPath validators and tehy all retrun the correct result.

I'm using: '//trackingNumber/concat("https://mysite.com/",./text())'
and I expected to get an array of:
https://mysite.com/1233244
https://mysite.com/3443534
If I take out the concat and use: //trackingNumber/text() it works and I get:
1233244
3443534

Here is the json of the action:

"Initialize_variable": {  
   "inputs": {  
        "variables": [  
            {  
                "name": "Result",  
                "type": "array",  
                "value": "@xpath(xml('<root><trackingNumbers><trackingNumber>1233244</trackingNumber><trackingNumber>3443534</trackingNumber></trackingNumbers></root>'),'//trackingNumber/concat(\https://mysite.com/\,./text())')"  
            }  
        ]  
    },  
    "runAfter": {},  
    "type": "InitializeVariable"  
}  

Does Logic App not support the concat()? If I just return the value using text() it works.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2022-02-10T11:44:12.93+00:00

    @Thomas Johnson You cannot use concat with xpath as first the concat will be evaluated and in case if there are any matching nodes or values then it will return the output (i.e. array values).

    In the below example you can see I have used concat and concat will give the output as //trackingNumber/text() and then it will find the matching path in my variable xml.

       xpath(xml(variables('xml')),concat('//trackingNumber','/text()'))  
    

    The above will give the output as below:
    1233244
    3443534

    If you change the expression as below the concat works correctly as it returns https://mysite.com//trackingNumber/text() but the xpath gives error as https://mysite.com//trackingNumber/text() is invalid xpath.

    xpath(xml(variables('xml')),concat('https://mysite.com/','//trackingNumber/text()'))  
    

    Therefore it doesn't give you the expected output as you are looking for. The alternative will be evaluating the xpath first xpath(xml(variables('xml')),'//trackingNumber/text()') and once you have the array iterate it and append the https://mysite.com/ to a new array variable.

    If you don't want to use multiple actions then you can offload this function to javascript inline code but this action needs an integration account on your logic app.

    You can refer to Reference guide to expression functions for Azure Logic Apps for different methods and their usage. Hope the above clears things up.
    Feel free to get back to me if you have any queries or concerns.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.