首页 文章

用于检查列表中是否存在2个元素文本值的Xpath查询

提问于
浏览
1

我试图找出一种方法来检查使用Xpath查询的列表中是否存在2个元素文本值 . 我目前仅限于Xpath 1.0 .

我有一个带有 subtree 的XML体,其中包含一个列表 . 它看起来像这样:

<tags>
      <tag>A</tag>
      <tag>B</tag>
      <tag>C</tag>
      <tag>E</tag>
</tags>

我希望有一个返回节点集的查询,如果该列表中的标记文本值等于'A'和'C' . (这会运行一个文件,其中包含我上面介绍的许多xml标记列表 .

这是我目前的最佳努力:

descendant-or-self::node()[local-name(.) = 'tag' and text() = 'A' and (preceding-sibling::text() = 'C' or following-sibling::text() = 'C')]

此问题可能是由于我的嵌套条件以及使用previous-sibling和following-sibling .

是否有可能以这种方式筑巢?

提前感谢您提供的任何帮助和见解!

2 回答

  • 0

    if(// tag / text()='A'和// tag / text()='C')// tag [text()='A'或text()='C'] else //空

  • 0

    这是我到达的解决方案:

    //descendant-or-self::node()[local-name(.) = 'tag' and text() = 'A' and (preceding-sibling::node()[text() = 'C'] or following-sibling::node()[text() = 'C']) ]
    

相关问题