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: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: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:value-of select="number(not(contains($t, '0')))"/>
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
-----Original Message-----
From: []On Behalf Of Gale Lee (EWU)
Sent: 13 February 2002 06:43
To: ''
Subject: [saxon] comparing node set


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.


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


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

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

<!ELEMENT xyz (vwx*)>

<!ELEMENT vwx (tuv?)>


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: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:template match="XYZ" mode="one">
  <xsl:param name="cNode"/>
  <xsl:copy-of select="current()/xyz"/>

  <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>