Project

Profile

Help

Union, intersect and except operators

Added by Adrian Bird 1 day ago

Do both sequences of nodes used in the operators union, intersect and except need to have a common ancestor?

When the 2 sequences are in separate variables I don't get the result I expect when using these operators.

If I use the XSLT implementations defined in the XPath and XQuery Functions and Operators 3.1 spec, https://www.w3.org/TR/xpath-functions-31/#union-intersect-except-on-values I do get the expected result.

Adrian


Replies (7)

Please register to reply

RE: Union, intersect and except operators - Added by Martin Honnen 1 day ago

Hi Adrian,

can you share an example of the code with two sequences in separate variables that goes wrong, showing us the minimal but complete code together with the example you get and the one you expect, as well as telling us which Saxon version and edition exactly you use?

It is also not quite clear why you first talk about the union, intersect and except operators that do set operations on sequences of nodes to then refer to the value based functions you have linked to.

https://www.w3.org/TR/xpath-31/#combining_seq

RE: Union, intersect and except operators - Added by Adrian Bird 1 day ago

I'm using SaxonJ-HE 12.5 Java.

It is easier to use a XSLT 3.0 test case than my actual example.

Using this test case, https://github.com/w3c/xslt30-test/blob/master/tests/attr/select/select-2016.xsl, if you duplicate the variable then use the new variable name on the right hand side of the operator you will see the difference in the results that are produced.

The expected results are in this file, https://github.com/w3c/xslt30-test/blob/master/tests/attr/select/_select-test-set.xml, line 1392.

Adrian

RE: Union, intersect and except operators - Added by Martin Honnen 1 day ago

Do you "duplicate" the variable as <t:variable name="var2" select="$var"/>?

Or do you create a second intermediary document by using e.g. <t:variable name="var2"><num1 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">1<num2>2<num3>3</num3> </num2> </num1> <num4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">4<num6>6</num6> </num4> <num5 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">5</num5></t:variable>

In the latter case you obviously have different nodes with a different identity so not sure why you would expect such a change of code to meet the test case result with nodes from a single document.

RE: Union, intersect and except operators - Added by Adrian Bird 1 day ago

The latter.

In the latter case you obviously have different nodes with a different identity so not sure why you would expect such a change of code to meet the test case result with nodes from a single document.

That is the basis of my question - if the 2 sequences of nodes on either side of the operator have a common ancestor they will have the same identity - what ever identity is being used.

But what identity is being used?

If they are defined in different variables then the namespace and element names are the same - but you say that they have different identities. Does that mean that the sequences of nodes on both side of the operator must generate the same id when using the generate-id() function?

Where is this defined in the specification?

Adrian

RE: Union, intersect and except operators - Added by Martin Honnen 1 day ago

See https://www.w3.org/TR/xpath-datamodel-31/#node-identity about the definition of node identity. There is also the is operator in XPath 2 and later that can be used to compare two nodes based on node identity, generate-id() is kind of a relict from XSLT 1.

https://www.w3.org/TR/xpath-31/#id-node-comparisons: "Node comparisons are used to compare two nodes, by their identity.." and "A comparison with the is operator is true if the two operand nodes are the same node; otherwise it is false. See [XQuery and XPath Data Model (XDM) 3.1] for the definition of node identity."

RE: Union, intersect and except operators - Added by Michael Kay about 19 hours ago

Without seeing your code it's impossible to see what you're doing wrong, but the usual sources of confusion with these operators are

(a) imagining that the compare nodes by value, not by identity

(b) failing to realise under what circumstances xsl:variable creates a new (copy of a) node.

Do remember that it's easier for us to help you debug your code if we can see the code.

RE: Union, intersect and except operators - Added by Adrian Bird about 14 hours ago

It was point (a).

Adrian

    (1-7/7)

    Please register to reply