首页 > 解决方案 > WiX 安装程序:将 xslt 与 heat.exe 一起使用时,如何在还使用匹配属性时找到匹配的子字符串?

问题描述

我有以下来源:

    <DirectoryRef Id="INSTALLDIR">
        <Component Id="Groupacuthin.exeAutoUpdate_acuthin.exe" Guid="*" Win64="no">
            <File Id="Groupacuthin.exeAutoUpdate_acuthin.exe" KeyPath="yes" Source="$(var.HARVESTDIR)\Groupacuthin.exeAutoUpdate\acuthin.exe" />
        </Component>
    </DirectoryRef>

我有以下模板,它可以找到 ID 为“INSTALLDIR”的所有 DirectoryRef,并且有一个 ID 为“Groupacuthin.exeAutoUpdate_acuthin.exe”的组件,并将 DirectoryRef Id 从“INSTALLDIR”更改为“TARGETDIR”:

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

这是正确的结果:

    <DirectoryRef Id="TARGETDIR">
        <Component Id="Groupacuthin.exeAutoUpdate_acuthin.exe" Guid="*" Win64="no">
            <File Id="Groupacuthin.exeAutoUpdate_acuthin.exe" KeyPath="yes" Source="$(var.HARVESTDIR)\Groupacuthin.exeAutoUpdate\acuthin.exe" />
        </Component>
    </DirectoryRef>

如果我的源有几个 DirectoryRefs,其组件 ID 如下所示:

<Component Id="Groupacuthin.exeAutoUpdate_acuthin.exe" Guid="*" Win64="no">
<Component Id="Groupfile1.exeAutoUpdate_file1.exe" Guid="*" Win64="no">
<Component Id="Groupfile2.exeAutoUpdate_file2.exe" Guid="*" Win64="no">

有没有办法更改模板以匹配任何具有 Id 的组件,其中 Id 包含子字符串“AutoUpdate”?

标签: xsltwixsubstringheat

解决方案


您可以contains在模板匹配规则中使用该函数:

<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR' and contains(wix:Component/@Id,'AutoUpdate')]">
  ...
</xsl:template>

然后您的所有样本都将匹配。


有没有办法更改模板以匹配任何具有 Id 的组件,其中 Id 包含子字符串“AutoUpdate”?

为此,请使用以下模板:

<xsl:template match="wix:Component[contains(@Id,'AutoUpdate')]">
  <xsl:element name="Component">
    <xsl:copy-of select="@*"/>
  </xsl:element>
</xsl:template>

如果没有Identity 模板,结果将是

<?xml version="1.0"?>
<Component Id="Groupacuthin.exeAutoUpdate_acuthin.exe" Guid="*" Win64="no"/>
<Component Id="Groupacuthin.exeAutoUpdate_acuthin.exe" Guid="*" Win64="no"/>
<Component Id="Groupfile1.exeAutoUpdate_file1.exe" Guid="*" Win64="no"/>
<Component Id="Groupfile2.exeAutoUpdate_file2.exe" Guid="*" Win64="no"/>

推荐阅读