XPath: Select 节点基于后代节点类型的深度

XPath: Select node based on depth of descendant node type

我需要 return 字符串 "A1" 或字符串 "A2" 取决于包含节点下方的 "B" 节点的最大深度:

<xmlDoc>
 <A>A1
  <B>
   <B>
    <B>
    </B>
   </B>
  </B>
  <B>
  </B>
</A>
<A>A2
 <B>
  <B>
  </B>
 </B>
  <B>
   <B>
   </B>
  </B>
 </A>
</xmlDoc>

descendant 轴似乎不适合确定 B 节点的 "depth"(例如:/xmlDoc/A[count(descendant::B)>2])。包含字符串 "A1" 的 "A" 节点的最大 "B" 节点深度为 3,但似乎有 4 "descendant" "B" 个节点...

如何根据第一个 "A" 节点中 "B" 节点的“3 深”出现构造 return 字符串 "A1" 的 XPath 表达式?

后代计算节点的所有子节点。如果你想要B节点链,就这么写

/xmlDoc/A[B[B[B]]]