omer khalid
omer khalid

Reputation: 895

Use of If/else statement in Xpath 2.0 in WSO2

I am using XPATH 2.0 in WSO2 Developer studio to perform some transformations on data in Payload Mediator. In one transformation i have to check that if an element exists in the legacy service response then print 'Yes,it does' otherwise 'No,it don't'.

I am using the following syntax.

if(fn:exists(//*/*[local-name()='HomePhone'])) then fn:concat('Yes','it does') 

else fn:concat('No','it dont')

It is giving me following error message. Error Message

I am confused about syntax. What's the correct way of using If/else in Xpath 2.0 in my particular scenario?

Note: "fn:concat" function works fine on it's own.

Upvotes: 2

Views: 3000

Answers (2)

mzwebstudio
mzwebstudio

Reputation: 42

Referring to Dharshana's comment above, fn:exists didn't work on my machine, infact the following code worked:

<filter xpath="//*/*[local-name()='HomePhone']" regex="false">

Upvotes: 1

Dharshana
Dharshana

Reputation: 1222

I believe you are trying to implement a synapse configuration in ESB to implement If then ELSE closure

You need to use a filter mediator to achieve this is ESB Synapse,

 <filter source="fn:exists(//*/*[local-name()='HomePhone'])" regex="false">
            <then>
               <log level="custom">
                  <property name="*********" value="NULL Property Value"/>
               </log>
            </then>
            <else>
               <log level="custom">
                  <property name="*********" value="NOT NULL Property Value"/>
               </log>
            </else>
         </filter>

Plese find filter mediator documentation on [1]

[1]. https://docs.wso2.com/display/ESB481/Filter+Mediator

Upvotes: 2

Related Questions