首页 > 解决方案 > wso2 foreach 循环永远不会进入

问题描述

我正在尝试让 wso2 foreach 循环工作。

<property expression="$ctx:xmlTransform" 

$ctx:xmlTransform 的值:

<magasin>
  <codeMagasin>20019</codeMagasin>
</magasin>
<magasin>
  <codeMagasin>20020</codeMagasin>
</magasin>
<magasin>
  <codeMagasin>20021</codeMagasin>
</magasin>

环形 :

<foreach expression="$ctx:xmlTransform//magasin" xmlns:ns="http://org.apache.synapse/xsd">
        <sequence>
            <log category="ERROR">
                <property expression="tessst" name="----Test foreach loop----"/>
            </log>
        </sequence>
</foreach>

我永远不会进入循环。

有任何想法吗 ?非常感谢。

标签: wso2wso2esbwso2carbonwso2ei

解决方案


也许问题在于“magasin”节点没有包含在一个父元素中。尝试用一些父元素(例如框)包装它,用父元素替换body,然后运行循环。

<enrich>
  <source type="inline" clone="true">
    <ns:box xmlns:ns="http://namespace"/>
  </source>
  <target type="property" property="box"/>
</enrich>
<enrich>
  <source clone="true" xpath="$ctx:xmlTransform"/>
  <target action="child" xpath="$ctx:box"/>
</enrich>
<enrich>
  <source type="property" clone="true" property="box"/>
  <target action="replace" type="body"/>
</enrich>
<foreach expression="//ns:box/magasin" xmlns:ns="http://namespace">
  <sequence>
    <log category="ERROR">
      <property expression="tessst" name="----Test foreach loop----"/>
    </log>
  </sequence>
</foreach>

推荐阅读