【发布时间】:2018-05-12 14:23:12
【问题描述】:
示例 1
<w:r>
<w:t>gene</w:t>
</w:r>
<w:ins>
<w:t>s</w:t>
</w:ins>
<w:r>
<w:t> </w:t> #I want to select this element
</w:r>
<w:del >
<w:t>house</w:t>
</w:del>
<w:r>
<w:t>had</w:t>
</w:r>
<w:r>
<w:t> </w:t> #I do not want to select this element
</w:r>
<w:ins >
<w:t>under</w:t>
</w:ins>
<w:del>
<w:t>in</w:t>
</w:del>
<w:r>
<w:t> </w:t> #I want to select this element
</w:r>
<w:ins>
<w:t>the</w:t>
</w:ins>
示例 2
<w:r>
<w:t>specific genes</w:t>
</w:r>
<w:ins>
<w:t>;</w:t>
</w:ins>
<w:del>
<w:t>,</w:t>
</w:del>
<w:r>
<w:t> </w:t> #I don't want to select this one
</w:r>
<w:r>
<w:t>SO</w:t>
</w:r>
我希望选择的元素如上所示。包含空格的 w:r 元素必须直接在 w:ins 或 w:del 元素之前,并且还必须直接跟在 w:ins 或 w:del 元素之后
我从下面的表达式开始,但它没有考虑到前面的兄弟可能是一个 w:del 元素。对于以下兄弟姐妹也是如此。它还必须检查元素之前或之后的元素,看看它是 w:ins 还是 w:del 元素。
search("//w:r[. = ' ' and previous-sibling::w:ins and following-sibling::w:del]")
但是,这似乎不起作用,因为它选择了所有包含空格的 w:r 元素。
我正在使用 Nokogiri。
有什么想法吗?
【问题讨论】:
标签: xml xpath nokogiri xpath-2.0