WSO2 ESB过滤器具有Xquery表达式内部的属性



我想在wso2属性介体中使用此表达式

sum(//datas//queryResponse[CODEAGENCE='01003']//NOMBER)

我已经这样做是为了计算而没有应用过滤器

fn:sum($ctx:datas//*[local-name()='queryResponse']//*[local-name()='NOMBRE'])

您的问题不清楚。您是否要使用包含XML的属性上的Xquery来计数Nombre字段的总和?如果是这样,这里是样本API。您可以从Postman或浏览器http://{yourwso2server}来调用它:8280/test/testso_57326564

结果是{" sum":" 340.0"}在示例数据上。

请注意,属性"数据"具有OM类型。

<api xmlns="http://ws.apache.org/ns/synapse" name="Test" context="/Test"> 
   <resource methods="GET" uri-template="/testSO_57326564">
      <inSequence>
         <log level="full"/>
         <payloadFactory media-type="xml">
            <format>
               <datas xmlns="">
                  <queryResponse>
                     <CODEAGENCE>01003</CODEAGENCE>
                     <NOMBRE>100</NOMBRE>
                  </queryResponse>
                  <queryResponse>
                     <CODEAGENCE>01003</CODEAGENCE>
                     <NOMBRE>240</NOMBRE>
                  </queryResponse>
                  <queryResponse>
                     <CODEAGENCE>01002</CODEAGENCE>
                     <NOMBRE>10000000</NOMBRE>
                  </queryResponse>
               </datas>
            </format>
            <args/>
         </payloadFactory>
         <property name="datas" expression="$body/*[1]" type="OM" description="property must be an OM type"/>         
         <property name="sum" expression="fn:sum($ctx:datas//queryResponse[CODEAGENCE=01003]/NOMBRE)"/>
         <payloadFactory media-type="json">
            <format>            {"sum":"$1"}            </format>
            <args>
               <arg evaluator="xml" expression="get-property('sum')"/>
            </args>
         </payloadFactory>
         <respond/>
      </inSequence>
   </resource>
</api>             

最新更新