我试图通过应用xml转换来清理heat.exe生成的wxs文件.
- <?xml version="1.0" encoding="utf-8"?>
- <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
- <Fragment>
- <DirectoryRef Id="APPFOLDER">
- <Component Id="cmp78E9FF58917B1844F3E9315A285F3147" Guid="SOME-GUID">
- <File Id="fil093D6D7CB723B5B62730D7B4E575F154" KeyPath="yes" Source="PQR.Some.dll" />
- </Component>
- <Component Id="cmp0B084126FAE7577FD84DB29766AC6C2B" Guid="SOME-GUID">
- <File Id="filB20C8708D7EB02EDFBCC4D70F9FE7F8A" KeyPath="yes" Source="ABC.Another.dll" />
- </Component>
- <Component Id="cmp83BB1954DECD7D949AAE4ACA68806EC3" Guid="SOME-GUID">
- <File Id="fil0E29FBFF7DB39F307A2EE19237A0A579" KeyPath="yes" Source="ABC.OneMore.dll" />
- </Component>
- </DirectoryRef>
- </Fragment>
- <Fragment>
- <ComponentGroup Id="AppFiles">
- <ComponentRef Id="cmp78E9FF58917B1844F3E9315A285F3147" />
- <ComponentRef Id="cmp0B084126FAE7577FD84DB29766AC6C2B" />
- <ComponentRef Id="cmp83BB1954DECD7D949AAE4ACA68806EC3" />
- </ComponentGroup>
- </Fragment>
- </Wix>
我想删除其子文件节点具有包含字符串’ABC’的Source属性的Component节点.我知道如何使用正确的匹配模式找到这样的节点.
因此,在删除Component节点之前,我想存储组件的Id,然后使用它来删除我刚刚记录的Id的ComponentRef节点.
有没有办法通过XML转换实现这一目标?我想我正在寻找一些可以创建变量的东西,说’X’来存储我删除的组件节点的Id,并使用’X’来查找要删除的ComponentRef节点.
你可以没有变量地做到这一点.像这样:
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:wi="http://schemas.microsoft.com/wix/2006/wi">
- <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
- <xsl:strip-space elements="*"/>
- <xsl:key name="kCompsToRemove"
- match="wi:Component[contains(wi:File/@Source,'ABC')]"
- use="@Id" />
- <xsl:template match="@* | node()">
- <xsl:copy>
- <xsl:apply-templates select="@* | node()"/>
- </xsl:copy>
- </xsl:template>
- <xsl:template match="*[self::wi:Component or self::wi:ComponentRef]
- [key('kCompsToRemove',@Id)]" />
- </xsl:stylesheet>
在样本输入上运行时,会产生:
- <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
- <Fragment>
- <DirectoryRef Id="APPFOLDER">
- <Component Id="cmp78E9FF58917B1844F3E9315A285F3147" Guid="SOME-GUID">
- <File Id="fil093D6D7CB723B5B62730D7B4E575F154" KeyPath="yes" Source="PQR.Some.dll" />
- </Component>
- </DirectoryRef>
- </Fragment>
- <Fragment>
- <ComponentGroup Id="AppFiles">
- <ComponentRef Id="cmp78E9FF58917B1844F3E9315A285F3147" />
- </ComponentGroup>
- </Fragment>
- </Wix>