Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

How to remove multiple nodes based on its value using XSLT?

$
0
0

How i can delete the key node from out put?

xml (there is multiple xmls same 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 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>

XSL

<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>

I try like below in the xsl

<xsl:templatematch="ProductType"/>

when i apply above template it delete <ProductType> from the output, but<xsl:apply-templates not working well

I need out put like below

<XMLResponse><ServiceProduct><ProductInfo><ProductCode>1001</ProductCode></ProductInfo><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME TWO</ProductName></AvailableProduct></ServiceProduct><ServiceProduct><ProductInfo><ProductCode>1001</ProductCode></ProductInfo><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME THREE</ProductName></AvailableProduct></ServiceProduct><ServiceProduct><ProductInfo><ProductCode>1002</ProductCode></ProductInfo><AvailableProduct><ProductName>PRODUCT NAME ONE</ProductName></AvailableProduct><AvailableProduct><ProductName>PRODUCT NAME TWO</ProductName></AvailableProduct></ServiceProduct></XMLResponse>

Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>