本文介绍了如何从xpath表达式获取实际的Node顺序(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的XPath表达式使用 preceding-sibling :: ,我得到的 NodeList 不在正确的顺序。我怎样才能得到正确的订单?示例:

If I have an XPath expression that use preceding-sibling::, I get the NodeList not in the right order. How can I get the right order? Example:

<library>
  <book name="book1">
    hello
  </book>
  <book name="book2">
    world
  </book>
  <book name="book3">
    !!!
  </book>
</library>

如果我尝试评估XPath表达式: / library / book [3 ] / previous-sibling :: book ,我收到此订单:

If I try to evaluate the XPath expression: /library/book[3]/preceding-sibling::book, I get this order:


  • book1

  • book2

但如果我尝试评估: / library / book [3] / previous-sibling :: book [1] ,我得到节点

But if I try to evaluate : /library/book[3]/preceding-sibling::book[1], I get the Node:


  • book2

那么,我怎样才能从这种表达式中获得真实的订单:

So, how can I get the real order from this kind of expression:

/ library / book [3] / preceding-sibling :: book

推荐答案

来自

关于使用特定XPath引擎评估某些XPath表达式后结果节点集的顺序,完全依赖于实现。在XSLT中,当指令处理按文档顺序排序的节点集时,会明确定义它。在XPath中,这是在:

About the order of the result node set after evaluation of some XPath expression with an specific XPath engine, that's completely implementation dependant. In XSLT, it's explicitly defined when instructions treats node set sorted in document order. In XPath this is how node sets are defined in http://www.w3.org/TR/xpath/#section-Introduction :

这就是为什么在标准DOM API中有获取有序和无序结果以及

That's why in the standard DOM API there are settings to get ordered and unordered results as well as in XQuery

这篇关于如何从xpath表达式获取实际的Node顺序(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 07:29