### Set difference, intersection and Union

The expression E1 except E2 selects all nodes that are in E1 unless they are also in E2. Both expressions must return sequences of nodes. The results are returned in document order. For example, @* except @note returns all attributes except the note attribute. The expression E1 intersect E2 selects all nodes that are in both E1 and E2. Both expressions must return sequences of nodes. The results are returned in document order. The expression E1 union E2 selects all nodes that are in either E1 or E2 or both. Both expressions must return sequences of nodes. The results are returned in document order. A complete example of the above expression would be as follows. Consider an XML document which looks like this:

    <nodes>
      <a>
        <connecteda>A</connecteda>
        <connecteda>B</connecteda>
        <connecteda>C</connecteda>
      </a>
      <b>
        <connectedb>B</connectedb>
        <connectedb>C</connectedb>
        <connectedb>D</connectedb>
      </b>
    </nodes>

Then an example of each of the expressions would be:

    data(/a/*) union data(/b/*)

result:

1. xs:string: A

2. xs:string: B

3. xs:string: C

4. xs:string: D

    data(/a/*) intersect data(/b/*)

result:

1. xs:string: B

2. xs:string: C

    data(/a/*) except data(/b/*)

result:

1. xs:string: D