How to combine this child element together using XSLT?

erickelmejor

New Member
If I have this input:\[code\]<root> <library id="L1"> <shelf1 id="1"> <book id="1" category="science"> <attributes> <year>2000</year> </attributes> <attributes> <author>xx</author> <year>2010</year> <isbn>001</isbn> </attributes> <attributes> <author>yy</author> <publisher>zz</publisher> <isbn>002</isbn> </attributes> <other>y</other> </book> <book id="2" category="science"> ... </book> </shelf1> <shelf2>...</shelf2> </library></root>\[/code\]expetced output:\[code\]<root> <library id="L1"> <shelf1 id="1"> <book id="1" category="science"> <attributes> <author>yy</author> <publisher>zz</publisher> <isbn>002</isbn> <year>2010</year> </attributes> <other>y</other> </book> <book id="2" category="science"> ... </book> </shelf1> <shelf2>...</shelf2> </library></root>\[/code\]I need to combine the element 'attributes' together. If two or more attributes exist, when the child of the attributes never exist before, we keep the child as new information, but if it exists previously we simply use the latest value.How to do such transformation in XSLT 1.0 or 2.0?Thanks very much for the help.John
 
Back
Top