[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:
http://www.xml.org//sites/www.xml.org/files/xslt_efficient_programming_techniques.pdf#page=3


Now I wanted to use it similarly for nodesets from different parts of
document.
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">
  <ns1>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>A</flag>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>B</flag>
  </ns1>
  <ns2>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>A</flag>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>C</flag>
  </ns2>
  <int />
  <uni>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>A</flag>
    <flag xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>B</flag>
  </uni>
</out>

$



<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:data="data"
>
<data:data>
  <flags>
    <flag>A</flag>
    <flag>B</flag>
  </flags>
  <flags>
    <flag>A</flag>
    <flag>C</flag>
  </flags>
</data:data>

  <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)]"/>

    <out>
      <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>
    </out>
  </xsl:template>

</xsl:stylesheet>


Mit besten Gruessen / Best wishes,

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

Current Thread