xslt - 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”?
解决方案
您可以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"/>
推荐阅读
- c# - Angular JS - 将字符串传递给 GET 方法并更新
- google-cloud-dataflow - 使用 gcloud 为数据流作业传递参数列表的语法
- vba - VBA 复选框不会将状态设置为 TRUE,但会设置为 FALSE
- c# - 为什么列表中的内容不改变?
- powershell - 继续查询 Powershell 开关参数
- python - 无法在vs代码中编译cpp和python文件
- java - 如何为 Amazon SNS (Java) 设置超时?
- python-3.x - 删除python中的停用词后,阿拉伯语单个字符仍然存在
- sql - 编写迭代自引用 SQL 查询
- python - 如何根据选择绘制熊猫分组(总和)数据