For Loop 数据编织 mulesoft 问题

For Loop dataweave mulesoft issue

我是 mulesoft 的新手,并且编写了用于遍历订单项(xml 中的产品线项)的 dataweave。但是,它不起作用,它只插入一个订单行项目,(订单行项目-product-lineitem) 有什么指点吗?

输入

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order xmlns="http://www.demandware.com/xml/impex/order/2006-10-31" order-no="00001101">
    <order-date>2020-07-09T12:55:28.663Z</order-date>
    <original-order-no>00001101</original-order-no>
    <product-lineitems>
        <product-lineitem>
            <product-id>65754</product-id>
        </product-lineitem>
        <product-lineitem>
            <product-id>65755</product-id>
        </product-lineitem>
    </product-lineitems>
</order>

数据编织

%dw 2.0
output application/java
ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
---
[{  
  Order_Confirmation_Number__c: payload.ns0#order.ns0#"current-order-no",
  "attributes": {
    "type": "PBSI__PBSI_Sales_Order__c",
    "referenceId": "SO"
  },                            
  "PBSI__Sales_Order_Lines__r": {
    "records": payload.*ns0#order.ns0#"product-lineitems" map((e,empindex) -> {                                                                     
      "attributes": {
        "type": "PBSI__PBSI_Sales_Order_Line__c",
        "referenceId": "SOL"
      },
      "PBSI__Item__c": "a0a1x000001PfWa",
      "PBSI__ItemDescription__c": e.ns0#"product-lineitem".ns0#"product-id"                                                                    
    })                                         
  } 
}]

您需要为多值节点添加 *product-lineitem 然后您可以在输出中获得两个值。此处有更多详细信息:https://docs.mulesoft.com/mule-runtime/4.3/dataweave-selectors

%dw 2.0
output application/java
ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
---
[{  
            Order_Confirmation_Number__c: payload.ns0#order.ns0#"original-order-no",
            attributes: {
                "type": "PBSI__PBSI_Sales_Order__c",
                "referenceId": "SO"
            },                          
            PBSI__Sales_Order_Lines__r: {
            records: payload.ns0#order.ns0#"product-lineitems".*ns0#"product-lineitem" map((e,empindex) -> {
                    "attributes": {
                        "type": "PBSI__PBSI_Sales_Order_Line__c",
                        "referenceId": "SOL"
                    },
                    "PBSI__Item__c": "a0a1x000001PfWa",
                    "PBSI__ItemDescription__c": e.ns0#"product-id"                 
            })                                         
        }   
}]