Skip to Content

Delete Duplicate records XSLT

Hi SDNites,

I have built an XSLT mapping for complex strutcure and there is a point where parent and child relationship exists and if in parent there is a duplicate tag then we do not need to process the child. Can you please advise how do I identify and remove the duplicate records during XSLT processing.

Regards,

Abhi

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Sep 20, 2017 at 07:41 PM

    Hi Abhishek!

    Wouldn't you please provide any example for your requirement?

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 20, 2017 at 08:13 PM

    Hi Evgeniy,

    Thanks for the response. Below is the sample file,

    <Tag0>

    <field0>value0 </field0>

    <Tag1>

    <field1> value1 </field1>

    <tag2>

    <field2> value2 </field2>

    <field3> value 3 </field3>

    <tag3>

    <field4> value4 </field4>

    <field5> value5 </field5>

    </tag3>

    <tag3>

    <field4> value6 </field4>

    <field5> value7 </field5>

    </tag3>

    </tag2>

    <tag2>

    <field2> value2 </field2>

    <field3> value 3 </field3>

    <tag3>

    <field4> value4 </field4>

    <field5> value5 </field5>

    </tag3>

    <tag3>

    <field4> value6 </field4>

    <field5> value7 </field5>

    </tag3>

    </tag2>

    </tag1>

    tag1 is multiple occurence,

    </tag0>

    Here my requirement is if field4 in <Tag2> is repeated anywhere in the XML then it has to be considered only once and corresponding child has to be read only.

    Regards,

    Abhi

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 21, 2017 at 08:50 AM

    Hi Abhishek!

    Here is example of transformation in which elements "Tag3" containing repeated values in subelement "field4" are removed from target document:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:template match="@* | node()">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="Tag3">
            <xsl:choose>
                <xsl:when test="not(field4/text() = preceding::Tag3/field4/text())">
                    <xsl:copy-of select="."/>
                </xsl:when>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded