Wix Heat harvest:使用转换删除包含过滤组件的目录

Wix Heat harvest: removing directories containing filtered components with transform

我有以下从 WiX harvest 输出的 .wxs(Ids ommitted)片段。

        <Directory Id="" Name="tr">
            <Component Id="" Guid="*">
                <File Id="" KeyPath="yes" Source="$(var.SourceDir)\tr\ZedGraph.resources.dll" />
            </Component>
        </Directory>
        <Directory Id="" Name="zh-cn">
            <Component Id="" Guid="*">
                <File Id="" KeyPath="yes" Source="$(var.SourceDir)\zh-cn\ZedGraph.resources.dll" />
            </Component>
        </Directory>
        <Directory Id="" Name="zh-tw">
            <Component Id="" Guid="*">
                <File Id="" KeyPath="yes" Source="$(var.SourceDir)\zh-tw\ZedGraph.resources.dll" />
            </Component>
        </Directory>
    </DirectoryRef>

并且以下转换将删除组件但保留空目录元素。我怎样才能删除它们?鉴于我不想一揽子删除所有目录元素。理想情况下,我想根据包含从搜索返回的组件 ID 来匹配它们。

<xsl:key name="zedResource-search" match="wix:Component[contains(wix:File/@Source, 'ZedGraph.resources.dll')]" use="@Id" />
<xsl:template match="wix:Component[key('zedResource-search', @Id)]" />
<xsl:template match="wix:ComponentRef[key('zedResource-search', @Id)]" />

This question 类似,但使用的目录名称我想避免为每个目录名称添加搜索,因为有相当多的语言变体。

一种方法是使用单独的模板来匹配 Directory 元素,其中所有子 Component 元素都在键中。你用 count

做这个比较
 <xsl:template match="wix:Directory[count(wix:Component) 
                                     = count(wix:Component[key('zedResource-search', @Id)])]" />

或者,你可以说你想删除 Directory,它没有 Component 引用,它不在键中(所以,双重否定)

<xsl:template match="wix:Directory[not(wix:Component[not(key('zedResource-search', @Id))])]" />