Reputation: 275
I have the following snippet of a .wxs(Ids ommitted) outputted from WiX harvest.
<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>
And the following transform will remove the components but leaves the empty directory elements. How can I remove them as well? Given that I do not want to blanket remove all directory elements. Ideally, I would like to match them based on containing the component Id that is returned from the search.
<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 is similar, but uses the directory names which i would like to avoid adding a search for each of these because there are quite a few language variants.
Upvotes: 0
Views: 2062
Reputation: 70648
One way to do this is use a separate template to match the Directory
element where all the child Component
elements are in the key. You do this comparison with a count
<xsl:template match="wix:Directory[count(wix:Component)
= count(wix:Component[key('zedResource-search', @Id)])]" />
Alternately, you can say you want to remove Directory
which don't have a Component
ref that are not in the key (so, a double negative)
<xsl:template match="wix:Directory[not(wix:Component[not(key('zedResource-search', @Id))])]" />
Upvotes: 1