|
Subject: Re: [xsl] Get the duplicates in a list From: "Bauman, Syd s.bauman@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 3 Jan 2025 12:37:51 -0000 |
Martin & Liam b
Are there significant advantages to your suggestions over the following?
(
( for $f in $fieldnames return if ( count( $fieldnames[ . eq $f ] ) gt 1 )
then $f else '' )
=> distinct-values()
)[. ne '']
I admit it is not simple, but strikes me as simpler. (Note that instead of the
null string, one could use any string that is guaranteed not to be a value. I
often like bbb (U+241C) or bbb (U+2205) for this kind of thing.
One could also probably use a test on that bifb that only looked at
preceding or following values of $fieldnames, which some folks might find more
readable.)
________________________________
>
> $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>
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.
---------
With pure XPath 3.1 you could try
let $fieldnames := ('TYPE', 'USAGE_CD', 'DIR', 'WGS_LAT', 'TYPE',
'WGS_LONG', 'TURN_DIR', 'DIR', 'TYPE'),
$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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Get the duplicates in a l, Liam R. E. Quin liam | Thread | Re: [xsl] Get the duplicates in a l, Martin Honnen martin |
| Re: [xsl] Get the duplicates in a l, Liam R. E. Quin liam | Date | Re: [xsl] Get the duplicates in a l, Martin Honnen martin |
| Month |