0

I have a requirement like this, Under the root tag 'Features' multiple feature elements are present.I need to remove duplicates. I have loaded its corresponding xsd in both source and target. But was not sure how to remove duplicates. My xml is a complex one, but to understand, I made here as simple.

Source ( input xml)

<features>
  ......(other fields)...
 <Datas>
   <feature> 1</feature>
   <feature> 2 </feature>
   <feature> 1 </feature>
   <feature> 3 </feature>
   <feature> 3 </feature>
  </Datas>  
</features> 

Target ( output xml)

<features>
   ....(other fields)....
  <ItemDetails>
   <feature> 1</feature>
   <feature> 2 </feature>
   <feature> 3 </feature> 
 </ItemDetails>

I was thinking, something need to do in For each element in DataMapper. But not sure how can be done or may be it is wrong

Please let me know if any short cut, crispy way to remove the duplicates. It will reduce my time in large. Mule version: 3.5.1 Thanks in advance.

star
  • 1,493
  • 1
  • 28
  • 61

2 Answers2

1

This cannot be accomplished with DataMapper, you need an ulterior XSLT transformer to remove duplicates, see the following stackoverflow question.

Community
  • 1
  • 1
Víctor Romero
  • 5,107
  • 2
  • 22
  • 32
  • Romero : I'm not getting. You ask me to keep flow variable before datamapper with HashSet() with which values?. Could you please explain bit more. If yo need more details I can able to give you. My xml is not simple, it is quite large. But All the other fields can able to achieve mapping, except this logic. So I have made my xml simpler here to cool understanding. – star Jan 21 '15 at 21:03
  • Romero: Please provide example script, It will help me more. Thanks in advance. – star Jan 21 '15 at 21:14
  • 1
    Sorry I missed the DataMapper part of your question. I don't think you can do this with datamapper. You might need a post processing with XSLT, see things like this: http://stackoverflow.com/questions/10912544/removing-duplicate-elements-with-xslt – Víctor Romero Jan 22 '15 at 00:38
  • Thanks a ton! for sharing the exact link. I have resolved the problem. You would have posted the link in Answer field. – star Jan 23 '15 at 00:01
0

I have resolved the problem in this way.

First I used Datamapper. It will gives as response but with duplicates. Finally I used Simple XSLT as described in this link Removing duplicate elements with XSLT( It removes duplicates alone) and make copy of remaining transformed field as such ( I used XSLT v1 in the link)

Hope It might helps for those facing the problem like me.

Community
  • 1
  • 1
star
  • 1,493
  • 1
  • 28
  • 61