如何使用 XPath 2.0 识别数字序列中的重复值? [英] How do you identify duplicate values in a numerical sequence using XPath 2.0?

查看:32
本文介绍了如何使用 XPath 2.0 识别数字序列中的重复值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XPath 表达式,它为我提供了如下所示的值序列:

1 2 2 3 4 5 5 6 7

使用 distinct-values() 很容易将其转换为一组唯一值 1 2 3 4 5 6 7 .但是,我要提取的是重复值列表 = 2 5.我想不出一个简单的方法来做到这一点.有人可以帮忙吗?

解决方案

使用这个简单的 XPath 2.0 表达式:

$vSeq[index-of($vSeq,.)[2]]

其中 $vSeq 是我们要在其中找到重复项的值序列.

有关此工作原理"的说明,请参阅:

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 unique values 1 2 3 4 5 6 7 using distinct-values() . However, what I want to extract is the list of duplicate values = 2 5. I can't think of an easy way to do this. Can anyone help?

解决方案

Use this simple XPath 2.0 expression:

$vSeq[index-of($vSeq,.)[2]]

where $vSeq is the sequence of values in which we want to find the duplicates.

For explanation of how this "works", see:

http://dnovatchev.wordpress.com/2008/11/16/xpath-2-0-gems-find-all-duplicate-values-in-a-sequence-part-2/

TLDR; This picture can be a visual explanation.

If the sequence is:

$vSeq  =  1,   2,   3,   2,   4,   5,   6,   7,   5,   7,   5

Then evaluating the above XPath expression produces: 2, 5, 7


这篇关于如何使用 XPath 2.0 识别数字序列中的重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆