How to select distinct <ServiceProduct>
using xsl?
This is my xml (like this there is many multiple XML's)
<XMLResponse><ServiceProduct><ProductInfo><ProductCode>1001</ProductCode></ProductInfo><ProductType>BLACK</ProductType><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME TWO</ProductName></AvailableProduct></ServiceProduct><ServiceProduct><ProductInfo><ProductCode>1001</ProductCode></ProductInfo><ProductType>BLACK</ProductType><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME TWO</ProductName></AvailableProduct></ServiceProduct><ServiceProduct><ProductInfo><ProductCode>1001</ProductCode></ProductInfo><ProductType>BLACK</ProductType><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME THREE</ProductName></AvailableProduct></ServiceProduct><ServiceProduct><ProductInfo><ProductCode>1002</ProductCode></ProductInfo><ProductType>BLACK</ProductType><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME TWO</ProductName></AvailableProduct></ServiceProduct></XMLResponse>
I need output like this:
<XMLResponse><ServiceProduct><ProductInfo><ProductCode>1001</ProductCode></ProductInfo><ProductType>BLACK</ProductType><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME TWO</ProductName></AvailableProduct></ServiceProduct><ServiceProduct><ProductInfo><ProductCode>1001</ProductCode></ProductInfo><ProductType>BLACK</ProductType><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME THREE</ProductName></AvailableProduct></ServiceProduct><ServiceProduct><ProductInfo><ProductCode>1002</ProductCode></ProductInfo><ProductType>BLACK</ProductType><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME TWO</ProductName></AvailableProduct></ServiceProduct></XMLResponse>
I am using this xsl now, but it is not working well:
<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:exsl="http://exslt.org/common"exclude-result-prefixes="exsl"><xsl:outputmethod="xml"indent="yes"/><xsl:keyname="ServiceByGroup"match="ServiceProduct"use="concat(ProductInfo/ProductCode,'|',ProductType)"/><xsl:templatematch="XMLResponse"><xsl:copy><xsl:variablename="msNodes"><xsl:apply-templatesselect="document('01_rs_01.xml')/*/ServiceProduct[ProductInfo/ProductCode != '']"></xsl:apply-templates></xsl:variable><ServiceList><xsl:apply-templatesselect="exsl:node-set($msNodes)/ServiceProduct [generate-id() = generate-id(key('ServiceByGroup', concat(ProductInfo/ProductCode,'|',ProductType))[1])]"/></ServiceList></xsl:copy></xsl:template><xsl:templatematch="node()|@*"><xsl:copy><xsl:apply-templatesselect="node()|@*"/></xsl:copy></xsl:template></xsl:stylesheet>