使用 Wix 工具集(版本 3.8)实用程序收获生成安装程序 xml 文件。我们想使用 xslt 选项删除包含其所有文件的文件夹以及对这些文件的任何引用。事实证明,后半部分是困难的;
这是 xml 的一部分;
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALL_ROOT">
<Directory Id="..." Name="MyCompany">
<Directory Id=".." Name="doc">
<Component Id="cmp20762D2CAD925E1B5974A3DD938BD5F3" Guid="..">
<File Id=".." KeyPath="yes" Source="index.html" />
</Component>
<Component Id="cmp1BE839006D9CC9F26ECCBEE5894EFC33" Guid="...">
<File Id=".." KeyPath="yes" Source="logo.jpg" />
</Component>
</Directory>
</Directory>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="Features">
<ComponentRef Id="cmp20762D2CAD925E1B5974A3DD938BD5F3" />
<ComponentRef Id="cmp1BE839006D9CC9F26ECCBEE5894EFC33" />
</ComponentGroup>
</Fragment>
</Wix>
使用此 xslt 我可以删除包含子元素的"文档"字典,但如何删除引用子组件 id 属性的组件参考?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node() | @*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Directory[@Name='doc']" />
</xsl:stylesheet>
将以下模板添加到样式表中。如果存在属性Name
对应于"doc"且Id
属性相同的Directory
元素,则它匹配ComponentRef
元素。
<xsl:template match="wix:ComponentRef[@Id = //wix:Directory[@Name='doc']/wix:Component/@Id]"/>
这会从输入 XML 中删除两个ComponentRef
元素,因为它们的两个 ID 都显示在 Directory[@Name='doc']
中。
样式表
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node() | @*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Directory[@Name='doc']" />
<xsl:template match="wix:ComponentRef[@Id = //wix:Directory[@Name='doc']/wix:Component/@Id]"/>
</xsl:stylesheet>
输出
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALL_ROOT">
<Directory Id="..." Name="MyCompany"/>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="Features"/>
</Fragment>
</Wix>
谢谢,这很有帮助
最终的解决方案包括双斜杠来处理带有子文件夹的文档文件夹。
<xsl:template match="wix:ComponentRef[@Id = //wix:Directory[@Name='doc']//wix:Component/@Id]"/