EXSLT - set:intersection

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

Function Syntax

node-set set:intersection(node-set, node-set)

Template Syntax

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

The set:intersection function returns a node set comprising the nodes that are within both the node sets passed as arguments to it.

The set:intersection template applies templates to these nodes in set:intersection 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:intersection:

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

Examples

Function

The following example shows how to use the set:intersection 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/intersection/index.html last modified 2002-11-12