I am trying to extract category-id when primary = true by grouping of product-id
%input payload application/xml
%output application/java
---
using (c=payload.catalog.*category-assignment default [])
((c default []) filter ($.@mode != "delete") groupBy $.@product-id map ({
(($ default []) filter ($.primary == 'true') map ({
field3:$.@category-id
}) when $.primary != null otherwise field3:"" ),
cat-id: $.@category-id joinBy "||" ,
primary-flag:$.primary
// (($ default []) filter ($.primary matches /true/) map ({
// //ur code here when equals to shipping charges
// field3:$.@category-id
// }) when $.primary != null otherwise [] ) ,
}))
I tried with multiple combination and filters. Filter generally works with xml attributes, but here giving exception
cast to com.mulesoft.weave.model.structure.ObjectSeq (java.lang.ClassCastException). Message payload is of type: ReceiverFileInputStream
Sample input -
<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="http://www.example.com/xml/impex/catalog/2006-10-31">
<category-assignment product-id="D711069" category-id="4160">
<primary>true</primary>
</category-assignment>
<category-assignment product-id="D711069" category-id="DANIEL_4160"/>
</catalog>
Any suggestions here?
I tried another set of transformation just for demo, not working -
%input payload application/xml
%output application/xml
---
Test:{((payload.catalog.*category-assignment default []) groupBy $.@product-id pluck {
product-id:$$,
cat-id: $.@category-id joinBy "||" ,
primary-flag:$[0].primary,
field3:$.@category-id[?($.primary == "true")]
})}