Removing duplicates in xml with xslt -
i need remove duplicates in following xml:
<listofrowidwithlistofbooks xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"> <rowidwithlistofbooks> <row_id>adoa-xssk</row_id> <listofbookinfo> <book> <booktype>brand</booktype> <bookname>jon</bookname> </book> <book> <booktype>brand</booktype> <bookname>jon</bookname> </book> </listofbookinfo> </rowidwithlistofbooks> </listofrowidwithlistofbooks>
can help?
this task can achieved using standard grouping solutions. not use single select statements known cause performance problems.
note reference identity.xsl
include stylesheet known identity transformation template.
[xslt 1.0]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:key name="k-books" match="book" use="concat(booktype,'|',bookname)"/> <xsl:include href="identity.xsl"/> <xsl:template match="listofbookinfo"> <listofbookinfo> <xsl:copy> <xsl:apply-templates select="book [generate-id() =generate-id(key('k-books',concat(booktype,'|',bookname))[1])]"/> </xsl:copy> </listofbookinfo> </xsl:template> </xsl:stylesheet>
[xslt 2.0]
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:include href="identity.xsl"/> <xsl:template match="listofbookinfo"> <listofbookinfo> <xsl:for-each-group select="book" group-by="concat(booktype,'|',bookname)"> <xsl:apply-templates select="."/> </xsl:for-each-group> </listofbookinfo> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment