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

Re: [xsl] Question on Kaysian method for set intersection

Subject: Re: [xsl] Question on Kaysian method for set intersection
From: Markus Abt <abt@xxxxxxxx>
Date: Wed, 28 Mar 2012 14:43:12 +0200

Hermann Stamm-Wilbrandt wrote:
> 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?

If the the flags are unique per nodeset, you can simply use:

<xsl:key name="flag" match="flag" use="."/>

<xsl:variable name="int" select="document('')//flags/flag[count(.|key('flag', .)[1])>1]"/>
<xsl:variable name="uni" select="document('')//flags/flag[count(.|key('flag', .)[1])=1]"/>

If the flags in one nodeset are not unique, you have to use additional
code to create unique nodesets, first.

Markus Abt

Current Thread