Search code examples
xsltwixheat

WiX Installer: Using xslt with heat.exe how do I change the value of the parent Id after finding a parent/child match?


I have the following source:

<DirectoryRef Id="INSTALLDIR">
    <Component Id="acuthin.exe" Guid="{0DAD4D00-A40E-420D-B90A-B23B89B72881}">

and I want to change INSTALLDIR to TARGETDIR:

<DirectoryRef Id="TARGETDIR">
    <Component Id="acuthin.exe" Guid="{0DAD4D00-A40E-420D-B90A-B23B89B72881}">

but only if Component Id="acuthin.exe". I tried the following:

<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR']/wix:Component[@Id='acuthin.exe']">
<xsl:copy>
  <xsl:attribute name="Id">TARGETDIR</xsl:attribute>
  <xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

but it changed the Id of Component instead of DirectoryRef:

<DirectoryRef Id="INSTALLDIR">
    <Component Id="TARGETDIR">

Is there a way to tell it to modify the DirectoryRef Id instead?

Here is my heat command line:

heat" dir "Files\Groupacuthin.exeAutoUpdate" -dr INSTALLDIR -var var.HARVESTDIR -gg -sw -nologo -scom -sreg -sfrag -srd -suid -cg "Groupacuthin.exeAutoUpdate" -t test.xslt -out "Components\Groupacuthin.exeAutoUpdate.wxs"

Here is the source before doing the template match:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="INSTALLDIR">
            <Component Id="acuthin.exe" Guid="{F48C7EB0-6192-4F92-8FCB-8DC8517572B5}">
                <File Id="acuthin.exe" KeyPath="yes" Source="$(var.HARVESTDIR)\acuthin.exe" />
            </Component>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="Groupacuthin.exeAutoUpdate">
            <ComponentRef Id="acuthin.exe" />
        </ComponentGroup>
    </Fragment>
</Wix>

Thanks!

Gary


Solution

  • What you want to modify is the Id attribute of DirectoryRef, but your template is actually selecting a Component that is a child of DirectoryRef.

    Change your template to:

    <xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR' and wix:Component/@Id='acuthin.exe']">
        <xsl:copy>
          <xsl:attribute name="Id">TARGETDIR</xsl:attribute>
          <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    

    See it working here: https://xsltfiddle.liberty-development.net/pPJ8LVx