Rebuild xml with xslt : copy all elements and apply function on some attributes



Here is a sample message:



<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://ift.tt/r5ut6F">
<id>xxx</id>
<atom:entry xmlns:atom="http://ift.tt/r5ut6F">
<atom:id>atom_id_01</atom:id>
<atom:content type="application/xml">
<event xmlns="http://event" xmlns:sample="sample" id="event_id_01">
<sample:product a="a_01_before" b="b__01before" />
</event>
</atom:content>
</atom:entry>
<atom:entry xmlns:atom="http://ift.tt/r5ut6F">
<atom:id>atom_id_02</atom:id>
<atom:content type="application/xml">
<event xmlns="http://event" xmlns:sample="sample" id="event_id_02">
<sample:product a="a_02_before" b="b_02_before" />
</event>
</atom:content>
</atom:entry>
</root>



  1. Extract entry node

  2. Apply a function (ConvertUtil.change(String value)) on product/@a and prodcut/@b.


The result should be like:



<entries>
<entry xmlns="http://ift.tt/r5ut6F">
<content>
<event xmlns="http://event" id="event_id_01">
<product a="a_01_after" b="b_01_after"/>
</event>
</content>
</entry>
<entry xmlns="http://ift.tt/r5ut6F">
<content>
<event xmlns="http://event" id="event_id_02">
<product a="a_02_after" b="b_02_after"/>
</event>
</content>
</entry>
</entries>


I tried in many ways and found out the namespaces were so annoying. Do I need to remove namespace first?


No comments:

Post a Comment