title: How to use XSLT to filter duplicates from another wxs file
body: <h1>What i have</h1>
  
  <p>I have a problem finding duplicate components using xslt.
  I am using heat to harvest 2 Projects. These projects share some references (.dll files). Now heat creates 2 Fragments</p>
  
  <ol>
  <li>ConfiguratorFiles.wxs</li>
  <li>ServiceFiles.wxs</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/ti8fZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ti8fZ.png" alt="WiX Project Structure"></a></p>
  
  <p>The ConfiguratorFiles.wxs gets created first and use a totaly basic filter:</p>
  
  <pre><code>  &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:key name="service-search" match="wix:Component[contains(wix:File/@Source, '.pdb')]" use="@Id" /&gt;
    &lt;xsl:template match="wix:Component[key('service-search', @Id)]"/&gt;
    &lt;xsl:template match="wix:ComponentRef[key('service-search', @Id)]" /&gt;
  </code></pre>
  
  <p>The output is totally fine, as i really want every dll to be copied and filter out pdb files.</p>
  
  <p>The Problem arises, when creating the ServiceFiles.wxs file. I just can't figure out how to check wether an element exists in the first wxs file.</p>
  
  <p><a href="https://github.com/wixtoolset/issues/issues/5609" rel="nofollow noreferrer">That</a> link provided the information, that i could embed a C# function, to execute some logic. That seems like a neat trick to me, but still i don't know how to search the contents of the other file.</p>
  
  <h2>Current ServiceFilter.xslt</h2>
  
  <p>The ServiceFilter.xslt is nearly the same as the ConfiguratorFiles.xslt, but i also filter out .exe Files, as i handle them manually
        
          
            
          
        </p>
  
  <pre><code>  &lt;!--Match and ignore .pdb files--&gt;
    &lt;xsl:key name="service-search" match="wix:Component[contains(wix:File/@Source, '.pdb')]" use="@Id" /&gt;
    &lt;xsl:template match="wix:Component[key('service-search', @Id)]"/&gt;
    &lt;xsl:template match="wix:ComponentRef[key('service-search', @Id)]"/&gt;
  
    &lt;!--Match and ignore .exe files--&gt;
    &lt;xsl:key name="exe-search" match="wix:Component[contains(wix:File/@Source, '.exe')]" use="@Id"/&gt;
    &lt;xsl:template match="wix:Component[key('exe-search', @Id)]"/&gt;
    &lt;xsl:template match="wix:ComponentRef[key('exe-search', @Id)]"/&gt;
  </code></pre>
  
  <h2>Example:</h2>
  
  <p>I have the following component in both (ConfiguratorFiles.wxs and ServiceFiles.wxs). This results in an error, that is why i need to filter duplicates.</p>
  
  <pre><code> &lt;Component Id="Foo.Base.dll" Guid="*"&gt;
       &lt;File Id="Foo.Base.dll" KeyPath="yes" Source="$(var.Foo.DSI.Configurator.TargetDir)\Foo.Base.dll" /&gt;
   &lt;/Component&gt;
  </code></pre>
  
  <h1>Actual Question</h1>
  
  <p>How to write a filter "ServiceFilter.xslt" that filters duplicates, so that ServiceFiles.wxs does not contain a file, that is contained in ConfiguratorFiles.wxs ?</p>
  
  <h1>Update</h1>
  
  <p>What i'm trying right now is to use a C# Method.
  Now i only need to figure out, how to get all Components in the first file to fill out the FindDuplicate method, as it currently filters everything :)</p>
  
  <pre><code>  &lt;!--Match and ignore duplicate components--&gt;
    &lt;xsl:key name="duplicate-search" match="wix:Component[user:FindDuplicate(wix:File/@Source)]" use="@Id"/&gt;
    &lt;xsl:template match="wix:Component[key('duplicate-search', @Id)]"/&gt;
    &lt;xsl:template match="wix:ComponentRef[key('duplicate-search', @Id)]"/&gt;
    &lt;msxsl:script language="C#" implements-prefix="user"&gt;
      &lt;![CDATA[  
       public bool FindDuplicate(string name){  
         return true;
       }  
        ]]&gt;
    &lt;/msxsl:script&gt;
  </code></pre>