0

在 XPath 中,我想关注某些元素并分析它们:

...
<field>aaa</field>
...
<field>bbb</field>
...
<field>aaa (1)</field>
...
<field>aaa (2)</field>
...
<field>ccc</field>
...
<field>ddd (7)</field>

我想找到文本内容的元素(除了可能的枚举之外,是唯一的。在 aboce 示例中,bbb、ccc 和 ddd。

以下 XPath 为我提供了唯一值:

distinct-values(//field[matches(normalize-space(.), ' \([0-9]\)$')]/substring-before(., '(')))

现在我想扩展它并对所有不同的值执行另一个 XPath,即计算有多少字段以它们中的任何一个开头并检索计数大于 1 的字段。

这些可能是等于该特定值的字段内容,或者它以该值开头并后跟“ (”。问题是在该 XPath 的第二部分中,我将引用该部分本身的上下文并同时适用于前一种情况。

在下面的 XPath 中,我将 - 而不是使用“。” 作为上下文 - 使用 c_outer 和 c_inner:

distinct-values(//field[matches(normalize-space(.), ' \([0-9]\)$')]/substring-before(., '(')))[count(//field[(c_inner = c_outer) or starts-with(c_inner, concat(c_outer, ' ('))]) > 1]

我不能使用“。” 出于显而易见的原因。但是我如何从内部表达式中的外部表达式引用特定的或当前的不同值?

这甚至可能吗?

4

1 回答 1

0

XQuery 可以做到,例如

  for $s 
  in distinct-values(
    //field[matches(normalize-space(.), ' \([0-9]\)$')]/substring-before(., '(')))
  where count(//field[(. = $s) or starts-with(., concat($s, ' ('))]) > 1
  return $s
于 2011-11-24T14:10:47.427 回答