EXSLT - set:difference

Implementer Page: set.difference.html
Function Package: set.difference.zip

Function Syntax

node-set set:difference(node-set, node-set)

Template Syntax

<xsl:call-template name="set:difference">
   <xsl:with-param name="nodes1" select="node-set" />
   <xsl:with-param name="nodes2" select="node-set" />
</xsl:call-template>

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.

The set:difference template applies templates to these nodes in set:difference mode. By default, the nodes are copied by this template, so that a result tree fragment consisting of the nodes is returned.

Implementations

The following XSLT processors support set:difference:

Implementations of set:difference are available in the following languages:

Examples

Function

The following example shows how to use the set:difference function:

Source

<doc>
   <city name="Paris"
         country="France" />
   <city name="Madrid"
         country="Spain" />
   <city name="Vienna"
         country="Austria" />
   <city name="Barcelona"
         country="Spain" />
   <city name="Salzburg"
         country="Austria" />
   <city name="Bonn"
         country="Germany" />
   <city name="Lyon"
         country="France" />
   <city name="Hannover"
         country="Germany" />
   <city name="Calais"
         country="France" />
   <city name="Berlin"
         country="Germany" />
</doc>

Stylesheet

<!--  Test set:intersection, difference  -->
<xsl:variable name="i"
              select="//city[contains(@name,'i')]" />
<xsl:variable name="e"
              select="//city[contains(@name,'e')]" />
<xsl:template match="/">
   <out>

    Containing i and e:
          <xsl:for-each select="set:intersection($i, $e)">
         <xsl:value-of select="@name" />
;
    
      </xsl:for-each>
     
    Containing i and no e:
          <xsl:for-each select="set:difference($i, $e)">
         <xsl:value-of select="@name" />
;
    
      </xsl:for-each>
 
    Containing e and no i:
          <xsl:for-each select="set:difference($e, $i)">
         <xsl:value-of select="@name" />
;
    
      </xsl:for-each>
<!--  test intersection and difference on empty sets  -->

    Containing i:
          <xsl:for-each select="set:difference($i, /..)">
         <xsl:value-of select="@name" />
;
    
      </xsl:for-each>

    Empty set:
          <xsl:for-each select="set:intersection($i, /..)">
         <xsl:value-of select="@name" />
;
    
      </xsl:for-each>
     
    Empty set:
          <xsl:for-each select="set:intersection(/.., $i)">
         <xsl:value-of select="@name" />
;
    
      </xsl:for-each>
 
    Empty set:
          <xsl:for-each select="set:difference(/.., $i)">
         <xsl:value-of select="@name" />
;
    
      </xsl:for-each>
   </out>
</xsl:template>

Result

<out xmlns:set="http://exslt.org/sets">
    Containing i and e:
    Vienna;
    Berlin;
         
    Containing i and no e:
    Paris;
    Madrid;
    Calais;
     
    Containing e and no i:
    Barcelona;
    Hannover;
    
    
    
    Containing i:
    Paris;
    Madrid;
    Vienna;
    Calais;
    Berlin;
    
    Empty set:
         
    Empty set:
     
    Empty set:
    </out>

http://www.exslt.org/set/functions/difference/index.html last modified 2002-11-12