I am working with MuleSoft DataWeave 2.0 to process an XML payload. I need to extract the second <wd:ID> element where the attribute wd:type equals "Learning_Course_ID".
Here is a sample XML input:
<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.test.report/test">
<wd:Report_Entry>
<wd:Worker_group>
<wd:user_email>[email protected]</wd:user_email>
</wd:Worker_group>
<wd:course_id wd:Descriptor="Preventing bribery, fraud and money laundering">
<wd:ID wd:type="WID">dummysdfg</wd:ID>
<wd:ID wd:type="Learning_Course_ID">MANUAL_COURSE-1-16</wd:ID>
<wd:ID wd:type="Learning_Course">Preventing bribery, fraud and money laundering</wd:ID>
</wd:course_id>
</wd:Report_Entry>
</wd:Report_Data>
I tried the following DataWeave script:
%dw 2.0
output application/json
ns wd urn:com.test.report/test
---
{
secondLearningCourseID:
payload.wd#Report_Data.wd#Report_Entry.wd#course_id."wd:ID"
filter ((item) -> item.@"type" == "Learning_Course_ID")[1]
}
But getting { "secondLearningCourseID": null }