How do you identify duplicate values in a numerical sequence using XPath 2.0?

前端 未结 4 866
北海茫月
北海茫月 2020-11-30 11:30

I have an XPath expression which provides me a sequence of values like the one below:

1 2 2 3 4 5 5 6 7

It is easy to convert this to a set of u

4条回答
  •  有刺的猬
    2020-11-30 12:09

    What about:

    distinct-values(
      for $item in $seq
      return if (count($seq[. eq $item]) > 1)
             then $item
             else ())
    

    This iterates through the items in the sequence, and returns the item if the number of items in the sequence that are equal to that item is greater than one. You then have to use distinct-values() to remove the duplicates from that list.

提交回复
热议问题