XPath/SQL Equivalents
SQL Equivalents
[edit | edit source]-XPath cannot do join-like queries, but can do union, intersection, subset, and difference like SQL
-XPath supports set operations like SQL using variations of the Union operation and the count function:
a UNION b: $a | $b
b UNION c: $b | $c
a INTERSECTION b: $a[count(.|$b) = count($b)]
a INTERSECTION c: $a[count(.|$c) = count($c)]
(Intersection takes the union of $b with any node in $a and returns the set of nodes in $a that are also in $b)
a DIFFERENCE b: $a[count(.|$b) != count($b)] | $b[count(.|$a) != count($a)]
a DIFFERENCE c: $a[count(.|$c) != count($c)] | $c[count(.|$a) != count($a)]
(Difference takes the union of the differences of $a with $b or $c and returns the set of nodes unique to $a versus $b or $c)
a SYM DIFFERENCE b: $a[count(. | $b) != count($b)] | $b[count(. | $a) != count($a)]
(Symmetrical difference takes the union of the differences from both sides and returns the set of nodes unique to both $a and $b)
a SUBSET OF b: count($b | $a) = count($b) and count($b) > count($a)
b SUBSET OF a: count($b | $a) = count($a) and count($a) > count($b)
(Subset means that the union of $a with $b returns the same set of nodes and either $a or $b is larger)
XPath can be embedded in an xpointer to make a smart url: