EXSLT - set:difference - Use Case 1

Category: example
XML Definition: set.difference.xml
Function or Template: function

Use Case

Source (view)

<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 (view)

<!--  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 (view)

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

Change History

Previous Version: ..NaN.html

VersionModifiedByDetails
12001-04-28Mike Kay

Tests functionality of set:intersection() and set:difference().

http://www.exslt.org/set/functions/difference/set.difference.use-case.1.html last modified 2001-04-28