The node-sets you are comparing each contain a single element node. These nodes have children and descendants, but the children and descendants are not members of the node-set in their own right.
 
When you compare two such (singleton) node-sets, you are comparing their string-values, that is the concatenation of all the descendant text nodes. For example, the following two elements will compare equal:
 
(a) <name>Peter <s>Smith</s></name>
(b) <person>Peter Smith</person>
 
This may not be the comparison you want. If you want the element names and structure to be the same, as well as the text content, you will have to write your own comparison logic. The best way to do this (in XSLT 1.0) would be as a recursive named template that returns the string "1" or "0" for true or false. It would look something like this:
 
<xsl:template name="compare">
  <xsl:param name="a"/>
  <xsl:param name="b"/>
  <xsl:choose>
  <xsl:when test="count($a) != count($b)">0</xsl:when>
  <xsl:when test="string($a) != string($b)">0</xsl:when>
  <xsl:when test="name($a) != name($b)">0</xsl:when>      
 <xsl:otherwise>
  <xsl:for-each select="$a">
    <xsl:variable name="pos" select="position()"/>
    <xsl:variable name="t">
      <xsl:call-template name="compare">
        <xsl:param name="a" select="."/>
        <xsl:param name="b" select="$b[$pos]"/>
      </xsl:call-template>
   </xsl:variable>
   <xsl:value-of select="number(not(contains($t, '0')))"/>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>
 
Not tested; and there are a few glitches, like that the element <a>3</a> will compare equal to the attribute a="3".
 
 
Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com
-----Original Message-----
From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net]On Behalf Of Gale Lee (EWU)
Sent: 13 February 2002 06:43
To: 'saxon-help@lists.sourceforge.net'
Subject: [saxon] comparing node set

Hi,

I am using saxon6.4.3 on Solaris.  I've been trying to understand the != and = operator for comparing node set to node set and reading Michael's book.  I cannot conclude my understanding.  How can make a 'deep' comparison such that two single nodes and its own children can be compared?   Thus, any string value differences from the attributes and element nodes within the tree can return true.  I really appreciate the help.

I capture sNode below from one file and cNode from another file.

sNode:

<xyz name="xyz">
   <vwx name="vwx1">
      <tuv>tuv text</tuv>
   </vwx>
   <vwx name="vwx2"/>
</xyz>

cNode:

<xyz name="xyz">
   <vwx name="vwx1">
      <tuv>tuv text</tuv>
   </vwx>
   <vwx name="vwx2"/>
</xyz>

Here is the dtd
<!ELEMENT XYZ (xyz*)>

<!ELEMENT xyz (vwx*)>
<!ATTLIST xyz name ID #REQUIRED>

<!ELEMENT vwx (tuv?)>
<!ATTLIST vwx name ID #REQUIRED>

<!ELEMENT tuv (#PCDATA)>

Here is the XSLT

<xsl:template match="XYZ">
  <xsl:for-each select="document('test2.xml')/XYZ/xyz">
    <xsl:apply-templates select="current()" mode="two">
      <xsl:with-param name="cNode" select="current()"/>
    </xsl:apply-templates>
  </xsl:for-each>
</xsl:template>

<xsl:template match="xyz" mode="two">
  <xsl:param name="cNode"/>
  <xsl:text>xyz two:</xsl:text>
  <xsl:apply-templates select="document('test1.xml')/XYZ" mode="one">
    <xsl:with-param name="cNode" select="$cNode"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="XYZ" mode="one">
  <xsl:param name="cNode"/>
  <xsl:text>&#xA;&#xA;sNode&#xA;&#xA;</xsl:text>
  <xsl:copy-of select="current()/xyz"/>

  <xsl:text>&#xA;&#xA;cNode&#xA;&#xA;</xsl:text>
  <xsl:copy-of select="$cNode"/>

  <xsl:text>&#xA;&#xA;TEST !=&#xA;&#xA;</xsl:text>
  <xsl:if test="($cNode != id($cNode/*/@name))">
    <xsl:text>Fall In</xsl:text>
  </xsl:if>
</xsl:template>