Why does distinct-values not yield distinct values on a non-atomized sequence

68 views Asked by At

Why does

(<benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170301</benefitEndDate>,
<benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170501</benefitEndDate>)/distinct-values(.)

yield 20170101 20170301 20170101 20170501 (i.e duplicates not eliminated)

but applying it to an atomized version of the sequence

distinct-values((20170701,20170301,20170701,20170501)) yields

20170701 20170301 20170501

1

There are 1 answers

0
michael On BEST ANSWER
(
  <benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170301</benefitEndDate>,
  <benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170501</benefitEndDate>
)/distinct-values(.)

is not the same as:

distinct-values(
  <benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170301</benefitEndDate>,
  <benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170501</benefitEndDate>
)

The latter returns the distinct-values for a sequence of elements.

Your code returns the distinct-values for each of these elements, it is like calling:

(
  distinct-values(<benefitStartDate>20170101</benefitStartDate>),
  distinct-values(<benefitEndDate>20170301</benefitEndDate>),
  distinct-values(<benefitStartDate>20170101</benefitStartDate>),
  distinct-values(<benefitEndDate>20170501</benefitEndDate>)
)

Another variant, that returns the result you expected is:

(
  <benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170301</benefitEndDate>,
  <benefitStartDate>20170101</benefitStartDate>,<benefitEndDate>20170501</benefitEndDate>
) => distinct-values()

Best

Michael