title: How can I write WiX XSLT which merges components
body: <p>I have a .wxs file which looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
      &lt;Fragment&gt;
          &lt;Directory&gt;
              &lt;Directory Id="d1"&gt;
                  &lt;Component Id="c1" ...&gt;
                      &lt;File Id="f1" KeyPath="yes" ... /&gt;
                  &lt;/Component&gt;
                  &lt;Component Id="c2" ...&gt;
                      &lt;File Id="f2" KeyPath="yes" ... /&gt;
                  &lt;/Component&gt;
                  &lt;Component Id="c3" ...&gt;
                      &lt;File Id="f3" KeyPath="yes" ... /&gt;
                  &lt;/Component&gt;
              &lt;/Directory&gt;
              &lt;Directory&gt;
                  &lt;Component&gt;
                  ...
              &lt;/Directory&gt;
              ...
          &lt;/Directory&gt;
      &lt;/Fragment&gt;
      &lt;Fragment&gt;
          &lt;ComponentGroup Id="cg1"&gt;
              &lt;ComponentRef Id="c1" /&gt;
              &lt;ComponentRef Id="c2" /&gt;
              &lt;ComponentRef Id="c3" /&gt;
              ...
          &lt;/ComponentGroup&gt;
      &lt;/Fragment&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>I want to 'merge' components above, i.e., I want to move files f2, f3 into component c1 and want to remove compoents c2, c3, plus component refs of c2, c3. In my actual source code there are much more directories including components. My intention is to reduce the number of components, i.e., for any pattern like</p>
  
  <pre><code>&lt;Directory&gt;
      &lt;Component&gt;
          &lt;File KeyPath="yes" /&gt;
      &lt;/Component&gt;
      &lt;Component&gt;
          &lt;File KeyPath="yes" /&gt;
      &lt;/Component&gt;
      ...
      &lt;Component&gt;
          &lt;File KeyPath="yes" /&gt;
      &lt;/Component&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>I want to reduce them into just one component(maybe the first component) including many files, like:</p>
  
  <pre><code>&lt;Directory&gt;
      &lt;Component&gt;
          &lt;File KeyPath="yes" /&gt;
          &lt;File /&gt;
          ...
          &lt;File /&gt;
      &lt;/Component&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>I know it's not recommemded to include many files in one component, but I want to do that to reduce the uninstallation time. Now, my installer takes pretty long time to uninstall and I assume it's because it has too many components(20,000 or so).</p>
  
  <p>Any help would be appreciated. Thank you.</p>