Skip to Content
0

Delete Duplicate records XSLT

Sep 20, 2017 at 03:25 PM

38

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Evgeniy Kolmakov Sep 20, 2017 at 07:41 PM
0

Hi Abhishek!

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

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded
Abhishek Gupta Sep 20, 2017 at 08:13 PM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Correction in above,

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

0

And how should your output structure look like?

Regards, Evgeniy.

0
Evgeniy Kolmakov Sep 21, 2017 at 08:50 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded