xsl-list
[Top] [All Lists]

[xsl] Re: How to remove duplicate record from XML

2016-09-28 13:14:13
I had tried with new xsl code insted of that for  '*How XSL will work If we
have more then one same record in XML, ignore them and extract only rest
data. my xsl code handling only duplicate value, i need only that record
which is not duplicate or more then one*'. Below is my new XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="w3.org/1999/XSL/Transform">;
<xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space
elements=""/> <xsl:key name="ccid" match="creations" use="id"/>
<xsl:template match="node() | @"> <xsl:copy> <xsl:apply-templates
select="node() | @*"/> </xsl:copy> </xsl:template> <xsl:template
match="creation[not(generate-id() = generate-id(key('ccid',
creations)[1]))]"/> </xsl:stylesheet>


Input:

<?xml version="1.0"
encoding="UTF-8"?><creations><creation><id>074</id></creation><creation><id>074</id></creation><creation><id>001</id></creation><creation><id>074</id></creation></creations>

Expected output:

  <creation>
  <id>001</id>
  </creation>


On Wed, Sep 28, 2016 at 6:33 PM, Rahul Singh 
<rahulsinghindia15(_at_)gmail(_dot_)com>
wrote:

How to remove duplicate record from XML, my code is working fine, i am
deleting duplicate, but i need only that XML which is not duplicate.

*Input:*

<?xml version="1.0" encoding="UTF-8"?>
<Contact-data>
   <Contact>
      <id>074</id>
   </Contact>
   <Contact>
      <id>074</id>
   </Contact>
*   <Contact>*
*      <id>001</id>*
*   </Contact>*
</Contact-data>

*XSL:*

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/
1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="/*">
        <xsl:for-each-group select="Contact" group-by="id">
            <xsl:sequence select="."/>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

*ExpectedOutput:*

<Contact-data>
   <Contact>
      <id>001</id>
   </Contact>
</Contact-data>

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>