Re: [xsl] Get the duplicates in a list

Subject: Re: [xsl] Get the duplicates in a list
From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 3 Jan 2025 11:23:07 -0000
On Fri, 2025-01-03 at 10:52 +0000, Roger L Costello costello@xxxxxxxxx
wrote:
> 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:

In the qt4 draft, thhis is duplicate-values($fieldnames)

This is described as being equivalent to
<xsl:for-each-group select="$values" group-by="." collation="{
$collation }">
  <xsl:sequence select="current-group()[2]"/>
</xsl:for-each>

https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-duplic
ate-values

We could make use of document order if the values were in elements with
a common ancestor:

let $fieldnames := <f> {
  ('TYPE', 'USAGE_CD', 'DIR', 'WGS_LAT', 'TYPE', 'WGS_LONG',
   'TURN_DIR', 'DIR', 'TYPE') ! <e>{.}</e>
} </f>
return distinct-values($fieldnames/e[preceding::e = .])

Not sure if thatbs simpler than Martinbs approach, but itbs more
XSLTish maybe.

liam

--
Liam Quin,B https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org

Current Thread