Re: [xsl] Get the duplicates in a list

Subject: Re: [xsl] Get the duplicates in a list
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 3 Jan 2025 11:04:45 -0000
Am 03.01.2025 um 11:52 schrieb Roger L Costello costello@xxxxxxxxx:
Hi Folks,

$fieldnames is a list of strings, e.g.,

('TYPE', 'USAGE_CD', 'DIR', 'WGS_LAT', 'TYPE', 'WGS_LONG', 'TURN_DIR',
'DIR', 'TYPE')

I want a list of the duplicates in $fieldnames:


('TYPE', 'DIR') <-- I don't want any duplicates in this list

Is there a simple XPath expression to obtain the list of duplicates in
$fieldnames?


With pure XPath 3.1 you could try


B  let $fieldnames := ('TYPE', 'USAGE_CD', 'DIR', 'WGS_LAT', 'TYPE',
'WGS_LONG', 'TURN_DIR', 'DIR', 'TYPE'),
B B B  $fieldnamesMap := map:merge($fieldnames!map:entry(., 1), map {
'duplicates' : 'combine' })
return map:for-each($fieldnamesMap, function($k, $v) { if ($v[2]) then
$k else ()})

Not sure whether it can be considered simple.

Current Thread