Hi Charmi,

instead of selecting the //symbol in the argument, I wrote a xpath
condition to select if symbol node has text else it will return empty
string.

<args>
          <arg evaluator="xml" expression="concat(substring(//symbol, 1 div
boolean(//symbol/text())), substring('', 1 div not(//symbol/text()) ))"/>
</args>

hope this will help

refer http://stackoverflow.com/a/7048664 for explanation

Regards
Senduran

On Mon, Jun 6, 2016 at 3:48 PM, Charmi Jayanga <[email protected]>
wrote:

> Hi,
>
> How to filter an empty response element in WSO2 ESB payload factory.
>
> *Proxy Service*
>
> <?xml version="1.0" encoding="UTF-8"?>
> <proxy xmlns="http://ws.apache.org/ns/synapse";
>        name="count_iterate"
>        transports="http,https"
>        statistics="disable"
>        trace="disable"
>        startOnLoad="true">
>    <target>
>       <inSequence>
>          <property name="it_count" value="0" scope="operation"/>
>          <iterate expression="//symbols/symbol" sequential="true">
>             <target>
>                <sequence>
>                   <property name="synapse_it_count"
>                             expression="get-property('operation', 
> 'it_count')"/>
>                   <script language="js">var cnt_str = 
> mc.getProperty('synapse_it_count');
>      var cnt = parseInt(cnt_str);
>      cnt++;
>      mc.setProperty('synapse_it_count', cnt.toString());</script>
>                   <property name="it_count"
>                             expression="get-property('synapse_it_count')"
>                             scope="operation"/>
>                   <aggregate>
>                      <completeCondition>
>                         <messageCount min="-1" max="-1"/>
>                      </completeCondition>
>                      <onComplete expression="//symbol">
>                         <log level="custom">
>                            <property name="number of symbols"
>                                      
> expression="get-property('operation','it_count')"/>
>                         </log>
>                         <payloadFactory media-type="xml">
>                            <format>
>                               <m xmlns="">
>                                  <n>$1</n>
>                               </m>
>                            </format>
>                            <args>
>                               <arg evaluator="xml" expression="//symbol"/>
>                            </args>
>                         </payloadFactory>
>                         <respond/>
>                      </onComplete>
>                   </aggregate>
>                </sequence>
>             </target>
>          </iterate>
>       </inSequence>
>    </target>
>    <description/>
> </proxy>
>
>
> *Scenario 1*
>
> *Sample Request*
>
> <symbols>
>    <symbol>WSO2</symbol>
> </symbols>
>
>
> *Sample Response*
>
> <m>
>    <n>WSO2</n>
> </m>
>
>
> *Scenario 2*
>
> *Sample Request*
>
> <symbols>
>    <symbol></symbol>
> </symbols>
>
>
> *Sample Response given from ESB*
>
> <m>
>    <n>
>       <symbol/>
>    </n>
> </m>
>
>
>
> Is there any way to avoid scenario 2? Or is there any workaround? I just need 
> the following response .
>
> *Sample Response expected*
>
> <m>
>    <n></n>
> </m>
>
>
> Regards
> Charmi
>
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
*Senduran *
Software Engineer,
WSO2, Inc.;  http://wso2.com/ <http://wso2.com/>
Mobile: +94 77 952 6548
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to