input xml
<address> <street>street line 1</street> <street>street line 2</street> <street>street line 3</street> <city>city</city> <postcode>0000</postcode> </address>
output xml required
<deliveryaddress> <da1>street line 1</da1> <da2>street line 2</da2> <da3>street line 3</da3> <city>city</city> <postcode>0000</postcode> </deliveryaddress>
how can use dataweave put each street element particular da element in outbound xml?
i've tried use *wildcard (address.*street) puts street elements child element:
<deliveryaddress> <da1> <street>street 1</street> <street>street 2</street> <street>street 3</street> </da1> <city>city</city> <postcode>0000</postcode> </deliveryaddress>
please ^_^
the * wildcard used reference repeated elements, in xml format. start point can sequentially solve problem:
- start expression
payload.address.*street
list of street. - however, error occur if directly use in current dataweave expression. therefore wrap expression inside bracket:
(payload.address.*street)
make object instead of array. - now need rename street tag correspond da(n). hence can utilize map operator iterate each record, , use brackets or quote marks,
() or '' or ""
enclose keys of output:
("da" ++ $$ + 1)
or "da$($$ + 1)"
both equally returning same result: da1, da2, da3, ...
therefore, complete expression field should be: (payload.address.*street map { ("da" ++ $$ + 1): $ })
Comments
Post a Comment