Hi Godwin,

According to [1] fn:sum is used to make sum of some xpath objects, for
example if the payload is [2], then "fn:sum(//order//item/@quantity)" will
return you the value 11. So I think you can't use fn:sum to just add two
numbers together.


[1] - https://www.w3.org/TR/xpath-functions/#func-sum
[2] - <order num="00299432" date="2006-09-15" cust="0221A">
<item dept="WMN" num="557" quantity="1" color="beige"/>
<item dept="ACC" num="563" quantity="1"/>
<item dept="ACC" num="443" quantity="2"/>
<item dept="MEN" num="784" quantity="1" color="blue/white"/>
<item dept="MEN" num="784" quantity="5" color="blue/red"/>
<item dept="WMN" num="557" quantity="1" color="sage"/>
</order>

Thanks,

On 6 August 2016 at 01:55, Godwin Shrimal <god...@wso2.com> wrote:

> Hi Udara,
>
> Yeah, we can use script mediator as an alternative, I need to know weather
> we can use fn:sum or is it not working in ESB.
>
> Thanks
> Godwin
>
> On Fri, Aug 5, 2016 at 3:19 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi Godwin,
>>
>> As a workaround following worked for me. I had to use parseInt, just
>> using + did not work for me.
>>
>> <property name="num1" value="10" scope="default" type="INTEGER"/>
>> <property name="num2" value="20" scope="default" type="INTEGER"/>
>> <script language="js"><![CDATA[
>>       var sum = parseInt(mc.getProperty("num1"))
>> +parseInt(mc.getProperty("num2"));
>>       var sum = mc.setProperty("testValue",sum.toString());
>>   ]]></script>
>>
>> On Sat, Aug 6, 2016 at 12:44 AM, Godwin Shrimal <god...@wso2.com> wrote:
>>
>>> Hi All,
>>>
>>> I have following sample config to sum two values
>>>
>>> <property name="num1" value="10" scope="default" type="INTEGER"/>
>>> <property name="num2" value="20" scope="default" type="INTEGER"/>
>>> <property xmlns:fn="http://www.w3.org/2005/xpath-functions"; xmlns:test="
>>> http://test";  xmlns:ns="http://org.apache.synapse/xsd"; name="testValue"
>>> expression="fn:sum($ctx:num1,$ctx:num2)"/>
>>>
>>> <log level="custom">
>>>       <property name="Total" expression="$ctx:testValue"/>
>>> </log>
>>>
>>>
>>> Total gives as 10 not 30, Is this a known bug or am I doing something
>>> wrong ?
>>>
>>>
>>> Thanks
>>> Godwin
>>>
>>>
>>> --
>>> *Godwin Amila Shrimal*
>>> Senior Software Engineer
>>> WSO2 Inc.; http://wso2.com
>>> lean.enterprise.middleware
>>>
>>> mobile: *+94772264165*
>>> linkedin: *http://lnkd.in/KUum6D <http://lnkd.in/KUum6D>*
>>> twitter: https://twitter.com/godwinamila
>>> <http://wso2.com/signature>
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> Dev@wso2.org
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> Blog: http://udaraliyanage.wordpress.com
>>
>
>
>
> --
> *Godwin Amila Shrimal*
> Senior Software Engineer
> WSO2 Inc.; http://wso2.com
> lean.enterprise.middleware
>
> mobile: *+94772264165*
> linkedin: *http://lnkd.in/KUum6D <http://lnkd.in/KUum6D>*
> twitter: https://twitter.com/godwinamila
> <http://wso2.com/signature>
>
> _______________________________________________
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Rajith Vitharana

Senior Software Engineer,
WSO2 Inc. : wso2.com
Mobile : +94715883223
Blog : http://lankavitharana.blogspot.com/
<http://wso2.com/signature>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to