[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Question on Kaysian method for set intersection

Subject: [xsl] Question on Kaysian method for set intersection
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Wed, 28 Mar 2012 13:16:15 +0200

I used Kaysian method as described in this document (section 1c), sofar:

Now I wanted to use it similarly for nodesets from different parts of
That does not work because /flags[1]/flag[.='A'] is not the same node
as /flags[2]/flag[.='A'].
Is it possible to get the flag with "A" for $int and flags for "A", "B" and
"C" for $uni?
If so, with keys?

$ xsltproc int-uni.xsl some.xml | tidy -q -xml
<?xml version="1.0"?>
<out xmlns:data="data">
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform">A</flag>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform">B</flag>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform">A</flag>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform">C</flag>
  <int />
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform">A</flag>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform">B</flag>


<xsl:stylesheet version="1.0"

  <xsl:template match="/">
    <xsl:variable name="ns1" select="document('')//flags[1]/flag"/>
    <xsl:variable name="ns2" select="document('')//flags[2]/flag"/>

    <xsl:variable name="int" select="$ns1[count(.|$ns2)=count($ns2)]"/>
    <xsl:variable name="uni" select="$ns1[count(.|$ns2)!=count($ns2)]"/>

      <ns1><xsl:copy-of select="$ns1"/></ns1>
      <ns2><xsl:copy-of select="$ns2"/></ns2>
      <int><xsl:copy-of select="$int"/></int>
      <uni><xsl:copy-of select="$uni"/></uni>


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Level 3 support for XML Compiler team and Fixpack team lead
WebSphere DataPower SOA Appliances
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

Current Thread