Reputation: 59
What would be the correct Dataweave expression to get "0011x000014VegoAAC" from XML below?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
<order-date>2020-07-10T08:57:05.076Z</order-date>
<current-order-no>00000907</current-order-no>
<product-lineitems>
<product-lineitem>
<net-price>54.17</net-price>
</product-lineitem>
</product-lineitems>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
</custom-attributes>
</order>
Upvotes: 0
Views: 642
Reputation: 4473
Custom-attribute looks like standard tag. Wrap it to the quotes and it will work fine. custom-attribute is an array which is indicated by asterisk in the DW transformation. From this array (line 19 creates it) we filter all items with attribute (indicated by @ character) equal sscAccountId.
Result is array with one element.
%dw 2.0
var payload =read('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
<order-date>2020-07-10T08:57:05.076Z</order-date>
<current-order-no>00000907</current-order-no>
<product-lineitems>
<product-lineitem>
<net-price>54.17</net-price>
</product-lineitem>
</product-lineitems>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
</custom-attributes>
</order>','application/xml')
output application/json
---
(payload.order."custom-attributes".*"custom-attribute")
filter (item) -> (item.@"attribute-id" ~= "sscAccountid")
Upvotes: 0