1

I have child element "Report_Entry" with sibling elements "employeeID, plan and startDate". I want to find distinct values using the sibling elements. If the combination of three elements is repeating, I want to eliminate any duplicate values.

I am not sure how to use distinct values based on multiple elements. I started going down the path of group-by by joining the strings and then split it once I get the group by value, but lost my way. group-by="string-join((employeeID,plan,startDate), '|')">

The XML data

<?xml version='1.0' encoding='UTF-8'?>
<Report_Data>
   <Report_Entry>
      <employeeID>0123</employeeID>
      <plan>plan1</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0123</employeeID>
      <plan>plan1</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0123</employeeID>
      <plan>plan2</plan>
      <startDate>2021-02-15</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0124</employeeID>
      <plan>plan1</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0124</employeeID>
      <plan>plan2</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0125</employeeID>
      <plan>plan1</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0125</employeeID>
      <plan>plan1</plan>
      <startDate>2021-04-22</startDate>
   </Report_Entry>
</Report_Data>

The output I am expecting. From the above output, employeeID 0123 with plan1 and startdat 0221-01-31 is repeating which I want to eliminate.

<?xml version='1.0' encoding='UTF-8'?>
<Report_Data>
   <Report_Entry>
      <employeeID>0123</employeeID>
      <plan>plan1</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0123</employeeID>
      <plan>plan2</plan>
      <startDate>2021-02-15</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0124</employeeID>
      <plan>plan1</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0125</employeeID>
      <plan>plan1</plan>
      <startDate>2021-01-31</startDate>
   </Report_Entry>
   <Report_Entry>
      <employeeID>0125</employeeID>
      <plan>plan1</plan>
      <startDate>2021-04-22</startDate>
   </Report_Entry>
</Report_Data>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Please post the XSL you've tried. – JSmart523 Nov 30 '21 at 02:48
  • JSmart523 - I first started a different approach. I grouped the data by using " group-by="string-join((employeeID,plan,startDate), '|')">" and hoped to try and split it using another XSLT and I lost my way. I tried few examples which are available online to get distinct which did not suit my example. – SreenivasBR Nov 30 '21 at 03:08
  • Please show us your attempt and how it failed or first look at the relevant examples in https://stackoverflow.com/tags/xslt-grouping/info. You seem to have the right grouping key and usually, if all you want is eliminate the duplicates, inside of `for-each-group` you only need to process the first item in the group which conveniently is the context item `.` so doing `` or `` will process only the first item of the group. – Martin Honnen Nov 30 '21 at 11:49

0 Answers0