【问题标题】:WiX Installer: Using xslt with heat.exe how do I find a matching substring when also using a match attribute?WiX 安装程序:将 xslt 与 heat.exe 一起使用时,如何在还使用匹配属性时找到匹配的子字符串?
【发布时间】:2020-02-13 22:34:44
【问题描述】:

我有以下来源:

    <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”的组件?

【问题讨论】:

    标签: xslt wix substring heat


    【解决方案1】:

    可以在模板匹配规则中使用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>
    

    没有身份模板,结果会是

    <?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"/>
    

    【讨论】:

    • 我尝试了 contains() 但它似乎没有使用 AutoUpdate 找到子字符串。它只输出源中的内容,而 INSTALLDIR 不会更改为 TARGETDIR。任何想法为什么它找不到 AutoUpdate 子字符串?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多