EXSLT - set:has-same-node

Implementer Page: set.has-same-node.html
Function Package: set.has-same-node.zip

Function Syntax

boolean set:has-same-node(node-set, node-set)

Template Syntax

<xsl:call-template name="set:has-same-node">
   <xsl:with-param name="nodes" select="node-set" />
   <xsl:with-param name="node" select="node-set" />
</xsl:call-template>

The set:has-same-node function returns true if the node set passed as the first argument shares any nodes with the node set passed as the second argument. If there are no nodes that are in both node sets, then it returns false.

Implementations

The following XSLT processors support set:has-same-node:

Implementations of set:has-same-node are available in the following languages:

Examples

Function

The following example shows how to use the set:has-same-node function:

Source

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

Stylesheet

<!--  Test set:has-same-node  -->
<xsl:variable name="a1"
              select="//city[@name='Vienna' or @name='Salzburg']" />
<xsl:variable name="a2"
              select="//city[@country='Austria']" />
<xsl:template match="/">
   <out>

    Test has-same-node() between two intersecting sets:
          <xsl:if test="set:has-same-node($a1,$a2)">OK</xsl:if>
;
    Test has-same-node() between two non-intersecting sets:
          <xsl:if test="not(set:has-same-node($a1,//city/@name))">OK</xsl:if>
;
    Test has-same-node() between two identical sets of namespace nodes:
          <xsl:if test="set:has-same-node((//city[1])/namespace::*,(//city[1])/namespace::*)">OK</xsl:if>
;        
    Test has-same-node() between two disjoint sets of namespace nodes:
          <xsl:if test="not(set:has-same-node((//city[1])/namespace::*,(//city[2])/namespace::*))">OK</xsl:if>
;        
  
   </out>
</xsl:template>

Result

<out xmlns:set="http://exslt.org/sets">
    Test has-same-node() between two intersecting sets:
    OK;
    Test has-same-node() between two non-intersecting sets:
    OK;
    Test has-same-node() between two identical sets of namespace nodes:
    OK;        
    Test has-same-node() between two disjoint sets of namespace nodes:
    OK;        
  </out>

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