Search code examples
xpathxpath-2.0

sequence (XPath 2.0) vs nodeSet (XPath 1.0)


why the concept node-set has been replaced by sequence in XPath 2.0? for what reason. What are the problems considered using the node-set? what is the advantage of the sequence from the node-set?

i say that : A node-set contains zero or more nodes, no node can appear in the node set more than once (that is, no duplicates are possible), and the nodes are not in any particular order.

and A sequence, by contrast, allows a node to appear more than once (duplicates are permitted), and the nodes in the sequence are in a particular order; in addition, sequences can contains nodes, atomic values, or any mixture of the two.


Solution

  • Firstly, the only kind of collection allowed in XPath 1.0 was a collection of nodes. XPath 2.0 also allows collections (sequences) of strings, numbers, and so on. Without this, functions such as tokenize() or string-to-codepoints() are impossible.

    Secondly, having only sets rather than sequences means you can't do things like binding a variable to the result of a sort operation.