简体   繁体   English

WiX 安装程序:将 xslt 与 heat.exe 一起使用如何在找到父/子匹配后更改父 ID 的值?

[英]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:我想将 INSTALLDIR 更改为 TARGETDIR:

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

but only if Component Id="acuthin.exe".但前提是 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:但它更改了组件的 Id 而不是 DirectoryRef:

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

Is there a way to tell it to modify the DirectoryRef Id instead?有没有办法告诉它修改 DirectoryRef Id?

Here is my heat command line:这是我的 heat 命令行:

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" 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加里

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.您要修改的是DirectoryRef 的Id 属性,但您的模板实际上选择了一个Component,它是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看到它在这里工作: https : //xsltfiddle.liberty-development.net/pPJ8LVx

Please try this code:请试试这个代码:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">

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

    <xsl:template match="DirectoryRef">
        <DirectoryRef>
            <xsl:apply-templates select="@* except @Id"/>
            <xsl:if test="(@Id='INSTALLDIR') and /Wix/Fragment/ComponentGroup/ComponentRef[@Id='acuthin.exe']">
                <xsl:attribute name="Id" select="'TARGETDIR'"/>
            </xsl:if>
            <xsl:apply-templates/>
        </DirectoryRef>
    </xsl:template>

你的@match="wix:DirectoryRef[@Id='INSTALLDIR']/wix:Component[@Id='acuthin.exe']" 而不是使用 @match="wix:DirectoryRef[@Id='INSTALLDIR' 和 wix :Component/@Id='acuthin.exe']"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM