2

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.

Community
  • 1
  • 1
omer khalid
  • 855
  • 1
  • 12
  • 39
  • Although "giving me error" could be anything, my guess is it's the apostrophe in `don't` that's giving you the grief. – biziclop Oct 21 '14 at 09:44
  • i have tried after removing it but same problem....... – omer khalid Oct 21 '14 at 09:52
  • [This answer](http://stackoverflow.com/a/23983340/592139) suggests that while WSO2 2.5.0 onwards supports XPath 2.0, it is disabled by default and needs some configuration to make it work. – Ian Roberts Oct 21 '14 at 10:39
  • 1
    I don't know WSO2, but the error definitely suggests that this expression is being processed by an XPath 1.0 parser. Though if it accepts the "fn:" prefix on concat(), that suggests some degree of 2.0-awareness. – Michael Kay Oct 21 '14 at 12:43

2 Answers2

2

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

Dharshana
  • 1,212
  • 1
  • 9
  • 18
1

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">