Re: [xsl] deep-equal behaves differently when node is stored in a variable

Subject: Re: [xsl] deep-equal behaves differently when node is stored in a variable
From: "Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 15 Apr 2025 23:01:29 -0000
Thank you very much, Martin and Michael! I was not aware of the differences you point out.
W.



On 4/15/25 18:13, Michael Kay michaelkay90@xxxxxxxxx wrote:
Or if you really want to variable to contain a copy of the node, rather than the original, then in place of xsl:sequence you could do

<xsl:variable name="person" as="node()">
   <xsl:copy-of select="."/>
</xsl:variable>

But I find it hard to think of a good reason for making a copy: people often use xsl:copy-of unnecessarily when xsl:sequence is more direct.

Michael Kay
Saxonica

On 15 Apr 2025, at 22:15, Martin Honnen martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:


On 15/04/2025 23:11, Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx wrote:
Dear list,

I would like to ask for your help with the following puzzling behavior that I have encountered. The situation is that I am testing whether the context node, which is a <person> element with child elements (first?, middle?, last), is deep-equal to one of a set of other nodes. I found the following solution:

some $p in //person satisfies deep-equal($p, .)

However, when I store the context node in a variable, like so:

<xsl:variable name="person">
\xA0\xA0 <xsl:copy-of select="."/>
</xsl:variable>

That creates a document node containing a copy of the context node, so you either need


<xsl:variable name="person" select="."/>

or, if you, for reasons I don't see, want to use the inner selection, use

<xsl:variable name="person" as="node()">

<xsl:sequence select="."/>

</xsl:variable>

and then make the comparison with the variable, like so:

some $p in //person satisfies deep-equal($p, $person)

then the test comes out false. Why is that? Why does it make a difference whether I store the context node in a variable or call it directly?


A document node is not deep-equal to an element node.

Current Thread