Wednesday, 12 March 2014

Remove Duplicate Nodes From XML Payload Using XSLT

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.

  • Created a BPEL process which input has multiple employee information. The xsd of the input payload looks like below.


  • 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