使用 XPATH 获取非空元素

问题描述:

我有以下 XML

<?xml version = "1.0" encoding = "UTF-8"?>
<root>
  <group>
    <p1></p1>
  </group>
  <group>
    <p1>value1</p1>
  </group>
  <group>
    <p1></p1>
  </group>
</root>

是否有可能获得最后一个有值的节点?在这种情况下,获取第二组/p1 的值.

is it possible to get the last the node with value? in this case get the value of the second group/p1.

/root/group/p1[text() 而 not(../following-sibling::group/p1/text())]

换句话说:获取具有文本且其父组后面没有包含非空 p1 元素的组节点的 p1 元素.

In other words: get the p1 elements that have text and whose group parents are not followed by group nodes that have non-empty p1 elements.