cancel
Showing results for 
Search instead for 
Did you mean: 

How to find an unique (distinct) value from incoming payload in SAP HCI/CPI

former_member230091
Participant
0 Kudos

Hello everyone,

I am getting incoming payload as mentioned below.

Totally 4 records.. 2 records for (EmpID =123) and 2 records for (EmpID = 111)

<Root>

<EMPLOYEE> <EmpID>123</EmpID> <Name>Test1</Name> </EMPLOYEE>

<EMPLOYEE> <EmpID>123</EmpID> <Name>Test2</Name> </EMPLOYEE>

<EMPLOYEE> <EmpID>111</EmpID> <Name>Test3</Name> </EMPLOYEE>

<EMPLOYEE> <EmpID>111</EmpID> <Name>Test4</Name> </EMPLOYEE>

</Root>

I need unique values of "EmpID" field and avoid duplicates.

So my expectation is to get only EmpID value of "123" one time and "111" one time and remove other duplicate values.

Could anyone give me groovy script code to achieve it or any other alternative approach.?

Regards,

Deva

Accepted Solutions (0)

Answers (1)

Answers (1)

yatanveersingh
Active Participant

Hi Deveraj,

Use the below XSLT.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <Root>
      <xsl:for-each-group select="/Root/EMPLOYEE" group-by="EmpID">
        <EMPLOYEE>
          <EmpID>
            <xsl:value-of select="EmpID"/>
          </EmpID>
          <Name>
            <xsl:value-of select="Name"/>
          </Name>
        </EMPLOYEE>
      </xsl:for-each-group>
    </Root>
  </xsl:template>
</xsl:stylesheet>

Regards,

Yatan