关于xml:XPath for parent中的属性不包含特定字符?

XPath for attribute in parent not containing a specific character?

确定父节点是否不包含特定字符的XPath表达式是什么?

给定以下XML:

1
2
3
4
5
6
7
8
9
10
<root>
  <parent id="parent_1" attr="ABC">
    <child id="child_11"/>
    <child id="child_12"/>
  </parent>
  <parent id="parent_2" attr="XYZ">
    <child id="child_21"/>
    <child id="child_22"/>
  </parent>
</root>

XPath表达式将如何测试哪些子代的父代在其属性attr中不包含字符Y?

作为ID为child_11child_12的孩子的答案。


这个XPath

1
//child[not(contains(../@attr,"Y"))]

将选择所有没有父元素且其attr属性值包含"Y"child元素,

1
2
<child id="child_11"/>
<child id="child_12"/>

按照要求。