4

Is it possible to include only certain file Extensions when using an xslt file to transform heat harvesting components using wix? I know I can exclude file extensions with the following:

<xsl:key name="exe-search" match="wix:Component[contains(wix:File/@Source, '.pdb')]" use="@Id" /> <!--.pdb-->

but is it possible to include several file types and exclude everything else (for example: .exe, .dll, .xml)?

Thank you!

dingdangdowney
  • 501
  • 1
  • 8
  • 22

1 Answers1

8

Sure. Inside the condition, you can use full expressions, like:

   contains(wix:File/@Source, '.pdb') 
or contains(wix:File/@Source, '.exe') 
or contains(wix:File/@Source, '.dll') 
or contains(wix:File/@Source, '.xml')

If it's just an handful, that should be maintainable. To aid readability, you can put newlines inside the match attribute value (or any attribute in general).


I would use it like this. Notice the poor man's ends-with trick.

The template matches unwanted Components and replaces them with nothing.

<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wi="http://schemas.microsoft.com/wix/2006/wi" 
    xmlns="http://schemas.microsoft.com/wix/2006/wi">

    <xsl:template match="wi:Component[not(
        contains(concat(wi:File/@Source,'|'), '.exe|') or
        contains(concat(wi:File/@Source,'|'), '.config|'))]">
     </xsl:template>


     <xsl:template match="node()|@*">
       <xsl:copy>
       <xsl:apply-templates select="@*"/>
       <xsl:apply-templates/>
       </xsl:copy>
     </xsl:template>
 </xsl:stylesheet>

Here's a heat command that it works with:

heat dir "%wix%\bin" -cg CompGroup -ag -t byext.xsl -o test.wxs
Tom Blodget
  • 20,260
  • 3
  • 39
  • 72
  • I just tried the following: and got every file in the folder – dingdangdowney Oct 17 '14 at 20:21
  • Unfirtunately this is case sensitive. Any idea how to integrate a function to confert the string to lowercase? I can put a translate with hard coded arguments in every line, but this can't be the solution. – milbrandt Jun 05 '23 at 11:39