Returning XPath correct order ( insted of document order)

后端 未结 1 1671
自闭症患者
自闭症患者 2021-01-07 04:49

So ive been given an assignment in my university of \"fixing\" XPath and get it to return the nodes in the correct order.

Ive been trying to find a way around writin

相关标签:
1条回答
  • 2021-01-07 04:57

    In XPath 1.0, there are no node sequences, only node sets. The XPath 1.0 specification doesn't define the order of nodes in a node set. Many APIs don't define it either, but invariably they return the nodes in the node-set in document order - not because XPath requires it, but because XSLT requires it, and XSLT has set the expectations for how XPath engines should behave.

    If you want node sequences with control over the ordering, you will have to move to XPath 2.0 (or XQuery 1.0, which is a superset of XPath 2.0). In XPath 2.0, the following expression returns what you want:

    reverse(/library/book[3]/preceding-sibling::book)
    
    0 讨论(0)
提交回复
热议问题