使用 XPath count() 和 contains() [英] Using XPath count() with contains()

查看:40
本文介绍了使用 XPath count() 和 contains()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下(次优)XML:

I am working with the following (suboptimal) XML:

<a>
  <b>
    <c>X:1 Y:0</c>
    <c>X:1 Y:0</c>
    <c>X:2 Y:0</c>
  </b>
  <b>
    <c>X:1 Y:0</c>
    <c>X:2 Y:0</c>
  </b>
</a>

我正在尝试使用 XPath 来计算内容包含 X:1 节点的数量:

I am trying to use XPath to count the number of <c> nodes whose contents contain X:1:

count(contains(/a/b/c, 'X:1'))

但是,这会返回错误而不是返回预期的 3 计数.

However, this returns an error rather than returning the expected count of 3.

我做错了什么?

推荐答案

这不是您使用 contains() 的方式.试试

That isn't how you use contains(). Try

count(/a/b/c[contains(., 'X:1')])

这篇关于使用 XPath count() 和 contains()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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