This question already has an answer here:
I have to transform the following xml content,
<Standards xmlns="http://ws.wso2.org/dataservice">
<Standard>
<ProductID>200057</ProductID>
<Prefix>ISO</Prefix>
<SNumber>1001</SNumber>
<DraftProducts>
<RelatedProduct>
<ProductID>1500163</ProductID>
</RelatedProduct>
</DraftProducts>
<ReferenceProducts>
<RelatedProduct>
<ProductID>263973</ProductID>
<RelationId>708519</RelationId>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
<RelatedProduct>
<ProductID>320056</ProductID>
<RelationId>934789</RelationId>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
</ReferenceProducts>
<RelatedIntProducts>
<RelatedProduct>
<ProductID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<RelationId>116881</RelationId>
<Relationship>Identical</Relationship>
<Designation>NEN ISO 1001</Designation>
</RelatedProduct>
<RelatedProduct>
<ProductID>208076</ProductID>
<RelationId>116886</RelationId>
<Relationship>Identical</Relationship>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
</RelatedIntProducts>
<S1>1001</S1>
<S2>1986</S2>
</Standard>
<Standard>
<ProductID>200058</ProductID>
<Prefix>ISO</Prefix>
<SNumber>1002</SNumber>
<DraftProducts>
<RelatedProduct>
<ProductID>1500167</ProductID>
</RelatedProduct>
</DraftProducts>
<ReferenceProducts>
<RelatedProduct>
<ProductID>263974</ProductID>
<RelationId>708519</RelationId>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
<RelatedProduct>
<ProductID>320052</ProductID>
<RelationId>934754</RelationId>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
</ReferenceProducts>
<RelatedIntProducts>
<RelatedProduct>
<ProductID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<RelationId>116837</RelationId>
<Relationship>Identical</Relationship>
<Designation>NEN ISO 1001</Designation>
</RelatedProduct>
<RelatedProduct>
<ProductID>208074</ProductID>
<RelationId>116843</RelationId>
<Relationship>Identical</Relationship>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
</RelatedIntProducts>
<S1>1005</S1>
<S2>1983</S2>
</Standard>
</Standards>
in to this output format,
<Standards xmlns="http://ws.wso2.org/dataservice">
<Standard>
<ProductID>200057</ProductID>
<Prefix>ISO</Prefix>
<SNumber>1001</SNumber>
<RelatedProducts>
<RelatedProduct>
<ProductID>1500163</ProductID>
<RelationType>DraftProducts</RelationType>
</RelatedProduct>
<RelatedProduct>
<ProductID>263973</ProductID>
<RelationId>708519</RelationId>
<RelationType>ReferenceProducts</RelationType>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
<RelatedProduct>
<ProductID>320056</ProductID>
<RelationId>934789</RelationId>
<RelationType>ReferenceProducts</RelationType>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
<RelatedProduct>
<ProductID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<RelationId>116881</RelationId>
<Relationship>Identical</Relationship>
<RelationType>RelatedIntProducts</RelationType>
<Designation>NEN ISO 1001</Designation>
</RelatedProduct>
<RelatedProduct>
<ProductID>208076</ProductID>
<RelationId>116886</RelationId>
<RelationType>RelatedIntProducts</RelationType>
<Relationship>Identical</Relationship>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
</RelatedProducts>
<S1>1001</S1>
<S2>1986</S2>
</Standard>
<Standard>
<ProductID>200058</ProductID>
<Prefix>ISO</Prefix>
<SNumber>1002</SNumber>
<RelatedProducts>
<RelatedProduct>
<ProductID>1500167</ProductID>
<RelationType>DraftProducts</RelationType>
</RelatedProduct>
<RelatedProduct>
<ProductID>263974</ProductID>
<RelationId>708519</RelationId>
<RelationType>ReferenceProducts</RelationType>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
<RelatedProduct>
<ProductID>320052</ProductID>
<RelationId>934754</RelationId>
<RelationType>ReferenceProducts</RelationType>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
<RelatedProduct>
<ProductID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<RelationId>116837</RelationId>
<RelationType>RelatedIntProducts</RelationType>
<Relationship>Identical</Relationship>
<Designation>NEN ISO 1001</Designation>
</RelatedProduct>
<RelatedProduct>
<ProductID>208074</ProductID>
<RelationId>116843</RelationId>
<RelationType>RelatedIntProducts</RelationType>
<Relationship>Identical</Relationship>
<Designation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</RelatedProduct>
</RelatedProducts>
<S1>1005</S1>
<S2>1983</S2>
</Standard>
</Standards>
For each standard I need to merge all the different types of RelatedProducts into one list named RelatedProducts. Also I need to keep the other stuffs as it is. I raised this question and got an answer here [1]. But now I need to get the RelationType for each RelatedProduct, which is the name of it's parent element. Can someone please help me to modify the answer I got here [1] so that I can add RelationType for each RelatedProduct element.
This XSLT will do the thing:
Result is: