Below an example of my current XML:
<products>
<product>
<id>1</id>
<name>Name 1</name>
<price>10.00</price>
<size>M</size>
<link>http://link1.com</link>
<stock>1</stock>
</product>
<product>
<id>1</id>
<name>Name 1</name>
<price>10.00</price>
<size>L</size>
<link>http://link1.com</link>
<stock>3</stock>
</product>
<product>
<id>1</id>
<name>Name 1</name>
<price>10.00</price>
<size>XL</size>
<link>http://link1.com</link>
<stock>2</stock>
</product>
<product>
<id>2</id>
<name>Name 2</name>
<price>30.00</price>
<size>M</size>
<link>http://link2.com</link>
<stock>3</stock>
</product>
<product>
<id>2</id>
<name>Name 2</name>
<price>30.00</price>
<size>L</size>
<link>http://link2.com</link>
<stock>2</stock>
</product>
</products>
I want to combine each product based on the id
and remove the duplicates with XSLT.
If the id
is the same, the nodes name
, price
and link
are always the same.
The nodes size
s and stock
can be different if the id
is the same. For these nodes (size
and stock
) these values should be summed up into the node (comma separated).
The result should look like this:
<products>
<product>
<id>1</id>
<name>Name 1</name>
<price>10.00</price>
<size>M,L,XL</size>
<link>http://link1.com</link>
<stock>1,3,2</stock>
</product>
<product>
<id>2</id>
<name>Name 2</name>
<price>30.00</price>
<size>M,L</size>
<link>http://link2.com</link>
<stock>3,2</stock>
</product>
</products>
I've searched and tried out several solutions but can't figure this one out.
Is there anyone who can help me out?
Thanks!