At the time of development sometimes it is required to remove the duplicate nodes from a XML payload depending upon some condition values. The following is a short example for the same.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW9l-erDZSzVu46UsyoODJHXZtKNJMM12eD5FaokrtaEZh1YN3n3XcKAL16IpCZkXefMuhyphenhyphengwjt7Xs_YIslaDwwRH5YDXsE7E9BNEIwRpKX27vc9zUPlYByK56SCgawxVR1h0rw9ODN4M/s1600/1.png)
- Created a BPEL process which input has multiple employee information. The xsd of the input payload looks like below.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW9l-erDZSzVu46UsyoODJHXZtKNJMM12eD5FaokrtaEZh1YN3n3XcKAL16IpCZkXefMuhyphenhyphengwjt7Xs_YIslaDwwRH5YDXsE7E9BNEIwRpKX27vc9zUPlYByK56SCgawxVR1h0rw9ODN4M/s1600/1.png)
- The input variable xml payload is looks like as given below.
- The below is XSLT code snippet which can be used to remove duplicate nodes which have the same employee id in the Input variable xml payload.
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="client:employee">
<xsl:if test="not(following::client:employee[client:empid=current()/client:empid])">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
- Below screenshot is the after transformation of the input variable.
Please give your comments on the same. Happy Coding. :)
No comments:
Post a Comment