Reputation: 35
I know this has been asked before, but what is the exact difference between the concept of a sequence in XSLT 2 and the earlier node set?
Also in which case/form are duplicates allowed in a sequence? If there are duplicates, would count(node1|node1) = 1
be true?
Upvotes: 1
Views: 72
Reputation: 163458
Expanding Max Toro's answer, there are two main differences between XSLT 1.0 node-sets and XSLT 2.0 sequences:
(1) sequences are ordered
(2) sequences may contain atomic values (such as strings and numbers) as well as nodes. (In 3.0 they may also contain other kinds of item, such as functions, maps, and arrays).
Rather than support both sets and sequences in 2.0, it was decided to only have sequences, but that some operations would cause a sequence of nodes to be sorted into document order with duplicates eliminated. The main operations that do this are:
(a) the union ('|'), intersect, and except operators.
(b) the path operator "/" (in the case where the right-hand operand returns nodes)
Because '|' eliminates duplicates, count($n|$n)
returns count($n)
(which is 1 if $n is a singleton). However, count(($m, $n))
returns count($m) + count($n)
, because the "," operator concatenates two sequences without eliminating duplicates. Similarly the new '!' operator does not eliminate duplicates, so count($m!$n)
is count($m)*count($n)
.
Upvotes: 3
Reputation: 28618
Sequences are ordered and may contain duplicates. The path operator (/
) eliminates duplicates and returns nodes in document order.
Sequences may contain atomic values.
Upvotes: 2