I don't think node-set() is the culprit here.
You've defined your variables t2-events
and specific-t2
using xsl:copy-of. So your variables should (and do) contain fresh copies (new element nodes) of the nodes selected by the select expressions on xsl:copy-of. It follows that none of the event
elements in the two variables is identical with any of the event
elements in the input, and similarly that the two copies of event 2 made in the two variables are two copies, not two references to a single copy.
Note that when we add a few more variables to your debugging code (nice job cutting the example down, by the way!), the union happens as we might expect, regardless of whether we use node-set() or not. (At least in xsltproc.)
After your initial two variables, I added two more:
<xsl:variable name="T2-EVENTS"
select="root/event
[eventType = 'TYPE2' and parent = '3']"/>
<xsl:variable name="SPECIFIC-T2"
select="root/event
[eventType = 'TYPE2' and id = '2']"/>
Then within your DEBUG element, I added:
<xsl:variable name="dummy3"
select="$T2-EVENTS | $SPECIFIC-T2 "/>
<xsl:variable name="dummy4"
select="ext:node-set($T2-EVENTS)
| ext:node-set($SPECIFIC-T2) "/>
and
<dummy3>
<xsl:comment>How many here?</xsl:comment>
<xsl:copy-of select="$dummy3"/>
</dummy3>
<dummy4>
<xsl:comment>How many here?</xsl:comment>
<xsl:copy-of select="$dummy4"/>
</dummy4>
When I run the resulting stylesheet with xsltproc, I get two elements in dummy3
and two in dummy4
; the call to node-set() made no difference.
(That said, I cannot see anything in the description of the node-set() function on the EXSLT site that says anything about node-set() preserving node identity or not preserving it. So I would be leery of relying on it either way.)