Re: set:difference() using two different node sets
Oleg Tkachenko <[email protected]>
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Organization | Multiconn Technologies |
| Message-ID | <[email protected]> |
[email protected] wrote: > We're trying to use set:difference() to compare two separate node-sets that > we create in variables. > > Most of the examples I see for this use partial node-sets from the same > parent node and compare those to get the difference (See the example found > at: http://www.exslt.org/set/functions/difference/index.html). My question > is do the two node sets need to have the same parent, or can they be from > two separate sources? It's not about parent, but about node identity. set:difference() function filters nodes basing on their identity. At least that's my understanding of the definition below and that's how EXSLT.NET implements it: "The set:difference function returns the difference between two node sets - those nodes that are in the node set passed as the first argument that are not in the node set passed as the second argument." > In effect we are doing something like: > > <xsl:variable name="v1"> > <xsl:for-each select="document('set1.xml')/*"> > <node id="@someId"/> > </xsl:for-each> > </xsl:variable> > <xsl:variable name="v2"> > <xsl:for-each select="document('set2.xml')/*"> > <node id="@id"/> > </xsl:for-each> > </xsl:variable> > > <xsl:copy-of select="set:difference( > msxsl:node-set($v1), msxsl:node-set($v2))"/> > > We are always getting the complete list found in $v1. We're not sure if it > is by design or a problem with the implementation of set:difference. msxsl:node-set($v1) and msxsl:node-set($v2)contain separate sets of nodes, so set:difference() is useless here. You seems to be looking for difference based on node equality. You can achieve it using something like <xsl:variable name="_v1" select="msxsl:node-set($v1)/*"/> <xsl:variable name="_v2" select="msxsl:node-set($v2)/*"/> <xsl:copy-of select="$_v1[not(. = $_v2)]"/> -- Oleg Tkachenko http://blog.tkachenko.com