骡分割器,使用xpath3表达式的foreach集合

时间:2015-05-13 14:00:45

标签: xml foreach mule

我有这个Mule流程:

<file:connector name="input" doc:name="input" autoDelete="false" />
<flow name="flow1">
    <file:inbound-endpoint connector-ref="input" responseTimeout="10000" doc:name="input" path="C:\test" pollingFrequency="100000" />
    <file:filename-wildcard-filter pattern="prod.xml" />
    <set-variable variableName="tempid" value="150" doc:name="Variable" />
    <foreach doc:name="For Each" collection="#[xpath3('//marketingdetailslist/marketdetails/*', payload, 'NODESET' )]">
        <enricher source="#[flowVars.tempid]" target="#[xpath3('//marketdetails/target')]" >
        <logger message="inside  enricher ~~~~~#[message.payloadAs(java.lang.String)]"  level="INFO" doc:name="Logger"/>
        </enricher>
    </foreach>

    <logger message="after enrichment  response~~~~~~.......#[message.payloadAs(java.lang.String)]"  level="INFO" doc:name="Logger"/>

</flow>

它接收此XML作为输入:

<marketingdetailslist>
       <marketdetails>
           <Jan>
               <target>100</target>
               <productname>Electronics</productname>               
           </Jan>
           <Feb>
              <target>50</target>
               <productname>Woodenitems</productname>
           </Feb>
       </marketdetails>
</marketingdetailslist>

这将是预期的输出,值会发生变化:

<marketingdetailslist>
       <marketdetails>
           <Jan>
               <target>150</target>
               <productname>Electronics</productname>               
           </Jan>
           <Feb>
              <target>150</target>
               <productname>Woodenitems</productname>
           </Feb>
       </marketdetails>
</marketingdetailslist>

我无法获得预期的输出。为了实现这一目标,我需要改变哪些内容?

1 个答案:

答案 0 :(得分:2)

您似乎正在尝试使用一组消息处理器模拟XSL-T Transformer。您可能会成功,但使用XSL-T会更好,因为它是为执行此类转换而设计的。