[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Duplicates in a sequence ?


Subject: Re: [xsl] Duplicates in a sequence ?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Mar 2015 11:23:58 -0000

Leo Studer leo.studer@xxxxxxxxxxx wrote:

I have a sequence and want to know whether there are duplicate values in it.

I came out with the following and think there must be an easy solution. Any suggestion?

let $sequence :=(1,12,14,17,22,12) return (count(distinct-values($sequence)) ne count($sequence))

I think is fine to compare the count, and http://www.xsltfunctions.com/xsl/functx_are-distinct-values.html has the same idea basically


<xsl:function name="functx:are-distinct-values" as="xs:boolean"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="seq" as="xs:anyAtomicType*"/>

  <xsl:sequence select="
   count(distinct-values($seq)) = count($seq)
 "/>

</xsl:function>


Current Thread