Mulesoft 条件语句

Mulesoft conditional statement

我有一个 XML,如果 XML 中存在 <custom-attribute attribute-id="sscAccountid">0011x0000152nlyAAA</custom-attribute> 标签,我想检查 Dataweave,该怎么做?

<?xml version="1.0" encoding="UTF-8"?>
<order xmlns="http://www.demandware.com/xml/impex/order/2006-10-31" order-no="00001503">
        <order-date>2020-07-24T13:15:09.654Z</order-date>
        <created-by>storefront</created-by>
        <original-order-no>000015034</original-order-no>
        <customer>
            <customer-no>00000001</customer-no>
            <billing-address>
                <first-name>abc</first-name>
                <last-name>Chioda</last-name>
                <address1>via Venezia 55</address1>
                <phone>+444</phone>
            </billing-address>
        </customer>
        <custom-attributes>
            <custom-attribute attribute-id="Adyen_pspReference">882595596510490G</custom-attribute>
            <custom-attribute attribute-id="Adyen_value">29999</custom-attribute>
            <custom-attribute attribute-id="sscAccountid">0011x0000152nlyAAA</custom-attribute>
            <custom-attribute attribute-id="sscSyncResponseText">
                <value>Successfully Exported</value>
            </custom-attribute>
            <custom-attribute attribute-id="sscSyncStatus">exported</custom-attribute>
            <custom-attribute attribute-id="sscid">8011x00000QaOFwAAN</custom-attribute>
        </custom-attributes>
</order>

我了解到您想确认具有示例结构的 XML 负载是否具有 order.custom-attributes.custom-attribute 元素,其属性 attribute-id 等于“sscAccountid ".

%dw 2.0
output application/json
fun hasAccountId(x) =sizeOf(x.order.'custom-attributes'  filterObject ($.@'attribute-id' == "sscAccountid") ) > 0
---
hasAccountId(payload)

输入的输出XML:

true