【问题标题】:Xpath find a node value matches in another node partiallyXpath在另一个节点中找到一个节点值部分匹配
【发布时间】:2020-09-01 08:39:54
【问题描述】:

我有这个 XML:

<ref>
  <label>MCLaren, 1996</label>
  <year>1997</year>
</ref>
<ref>
  <label>Dhanvanth, 2016</label>
  <year>2016</year>
</ref>
<ref>
  <label>Darwin2 2001</label>
  <year>1997</year>
</ref>

如果需要显示年份值与标签不匹配,我想检查相应标签中的上述标签值“1997”与上述标签值“MCLaren,1996”,XPath 中预期的答案

我试过下面的代码:

/ref[descendant::label != descendant::year[contains(text(),'')]]

【问题讨论】:

  • 你的问题解决了吗?

标签: xml xpath xpath-2.0 mismatch xpath-1.0


【解决方案1】:

我不确定,如果我正确理解了您想要的内容,但以下 XPath:

/root/ref[not(contains(descendant::label/text(), descendant::year/text()))]

返回所有参考,其中年份文本不包含在标签文本中

输出

<ref>
  <label>MCLaren, 1996</label>
  <year>1997</year>
</ref>
<ref>
  <label>Darwin2 2001</label>
  <year>1997</year>
</ref>

【讨论】:

  • 非常感谢..我现在明白这个概念了..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-23
  • 2013-07-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多