我在xml下方,需要使用m子数据编织转换对其进行转换。
<Colleges>
<College>
<name>C1</name>
<Students>
<Student>
<name>s1</name>
<dept>d1</dept>
</Student>
<Student>
<name>s2</name>
<dept>d2</dept>
</Student>
<Student>
<name>s3</name>
<dept>d3</dept>
</Student>
<Student>
<name>s4</name>
<dept>d3</dept>
</Student>
</Students>
</College>
</Colleges>
我想通过从xml上方获取唯一的部门将其转换为xml下方。
<Departments>
<name>d1</name>
<name>d2</name>
<name>d3</name>
</Departments>
任何建议都会有所帮助。
答案 0 :(得分:1)
这应该可以解决问题:
%dw 1.0
%output application/xml
---
Departments: payload.Colleges.College.Students.*Student mapObject (
name: $.dept
) distinctBy $.name
将示例有效负载发布到localhost:8081 /
<flow name="departments">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
---
Departments: payload.Colleges.College.Students.*Student mapObject (
name: $.dept
) distinctBy $.name]]></dw:set-payload>
</dw:transform-message>
</flow>