Rahul
Rahul

Reputation: 170

using mule variable value in xpath expression

I have a variable set as

<set-variable variableName="productIdvar" value="#[xpath://productId]" doc:name="Variable" />

On logging its coming right,

I want to use the value of the variable productIdvar in my xpath expression,

<when expression="//*[local-name()='itemid']=?" evaluator="xpath">

or

<when expression="#[xpath://*[local-name()='itemid']=?]">

What should i use in place of ? to get the value of the variable?

Thanks Rahul.

Upvotes: 0

Views: 3365

Answers (4)

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8321

You can use XPATH3 and try something like this
#[xpath3('/products/validlity')== flowVars.productIdvar]
Xpath3 reference :- https://developer.mulesoft.com/docs/display/current/XPath

Upvotes: 0

ThomasRS
ThomasRS

Reputation: 8287

If your MEL gets a bit messy, try my mule-module-dxpath - an XPath transformer which dynamicaly resolves XPath variables.

Upvotes: 0

user1760178
user1760178

Reputation: 6697

The following expression should work for you.

<when expression="#[xpath('//*[local-name()=\'itemid\']').text == productIdvar ]">

This way you should be able to compare the result of the xpath with the "productIdVar" variable.

Hope this helps.

Upvotes: 2

Charu Khurana
Charu Khurana

Reputation: 4551

<when expression="#[xpath('//*[local-name()=itemid]') == productIdvar ]">

Note that there are no quotation marks surrounding itemid in expression

Upvotes: 0

Related Questions