如何编写合并组件的WiX XSLT
我有一个.wxs文件,如下所示:如何编写合并组件的WiX XSLT,xslt,wix,Xslt,Wix,我有一个.wxs文件,如下所示: <?xml version="1.0" encoding="utf-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Fragment> <Directory> <Directory Id="d1"> <Component Id="c1" ...&
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<Directory>
<Directory Id="d1">
<Component Id="c1" ...>
<File Id="f1" KeyPath="yes" ... />
</Component>
<Component Id="c2" ...>
<File Id="f2" KeyPath="yes" ... />
</Component>
<Component Id="c3" ...>
<File Id="f3" KeyPath="yes" ... />
</Component>
</Directory>
<Directory>
<Component>
...
</Directory>
...
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="cg1">
<ComponentRef Id="c1" />
<ComponentRef Id="c2" />
<ComponentRef Id="c3" />
...
</ComponentGroup>
</Fragment>
</Wix>
...
...
...
我想“合并”上面的组件,即,我想将文件f2、f3移动到组件c1中,并想删除组件c2、c3以及c2、c3的组件引用。在我的实际源代码中,包含组件的目录多得多。我的目的是减少组件的数量,即,对于任何模式,如
<Directory>
<Component>
<File KeyPath="yes" />
</Component>
<Component>
<File KeyPath="yes" />
</Component>
...
<Component>
<File KeyPath="yes" />
</Component>
</Directory>
...
我想将它们简化为一个组件(可能是第一个组件),包括许多文件,如:
<Directory>
<Component>
<File KeyPath="yes" />
<File />
...
<File />
</Component>
</Directory>
...
我知道不建议在一个组件中包含多个文件,但我想这样做以减少卸载时间。现在,我的安装程序需要很长时间才能卸载,我想这是因为它有太多的组件(20000个左右)
任何帮助都将不胜感激。谢谢。我认为实现这一点的最简单方法是使用
以下同级轴:
样式表
输入
输出
我认为实现这一点的最简单方法是使用以下同级轴:
样式表
输入
输出
这是我的答案。谢谢你,埃罗·海伦纽斯
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
exclude-result-prefixes="wix">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:key name="kRemoveComps"
match="wix:Directory/wix:Component[position()>1]" use="@Id" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Directory">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="wix:Directory" />
<xsl:apply-templates select="wix:Component[1]" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component[1]">
<xsl:copy>
<!-- Attr. -->
<xsl:apply-templates select="@*" />
<!-- File in this Component -->
<xsl:apply-templates select="wix:File" />
<!-- Files in siblings -->
<xsl:apply-templates select="../wix:Component[position()>1]/wix:File" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component[position()>1]/wix:File">
<xsl:copy>
<!-- Removing KeyPath Attr. -->
<xsl:apply-templates select="@*[not(name()='KeyPath')]|node()" />
</xsl:copy>
</xsl:template>
<!-- Removing ComponentRef -->
<xsl:template match="wix:ComponentRef[key('kRemoveComps', @Id)]" />
</xsl:stylesheet>
这是我的答案。谢谢你,埃罗·海伦纽斯
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
exclude-result-prefixes="wix">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:key name="kRemoveComps"
match="wix:Directory/wix:Component[position()>1]" use="@Id" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Directory">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="wix:Directory" />
<xsl:apply-templates select="wix:Component[1]" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component[1]">
<xsl:copy>
<!-- Attr. -->
<xsl:apply-templates select="@*" />
<!-- File in this Component -->
<xsl:apply-templates select="wix:File" />
<!-- Files in siblings -->
<xsl:apply-templates select="../wix:Component[position()>1]/wix:File" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component[position()>1]/wix:File">
<xsl:copy>
<!-- Removing KeyPath Attr. -->
<xsl:apply-templates select="@*[not(name()='KeyPath')]|node()" />
</xsl:copy>
</xsl:template>
<!-- Removing ComponentRef -->
<xsl:template match="wix:ComponentRef[key('kRemoveComps', @Id)]" />
</xsl:stylesheet>
请注意,您必须处理孤立的ComponentRef
元素,为了避免使用WiX编译器,这些元素也应该被删除complain@YanSklyarenko:谢谢你指出这一点!我不熟悉WiX。要删除孤立的
元素,只需将
添加到样式表中即可。或者有必要删除整个
或
元素吗?请注意,您必须处理孤立的ComponentRef
元素,为了避免WiX编译器,也应该删除这些元素complain@YanSklyarenko:谢谢你指出这一点!我不熟悉WiX。要删除孤立的
元素,只需将
添加到样式表中即可。或者是否需要删除整个
或
元素?
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<Directory>
<Component Id="c1">
<File Id="f1" KeyPath="yes"/>
<File Id="f2" KeyPath="yes"/>
<File Id="f3" KeyPath="yes"/>
</Component>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="cg1">
<ComponentRef Id="c1"/>
<ComponentRef Id="c2"/>
<ComponentRef Id="c3"/>
</ComponentGroup>
</Fragment>
</Wix>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
exclude-result-prefixes="wix">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:key name="kRemoveComps"
match="wix:Directory/wix:Component[position()>1]" use="@Id" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Directory">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="wix:Directory" />
<xsl:apply-templates select="wix:Component[1]" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component[1]">
<xsl:copy>
<!-- Attr. -->
<xsl:apply-templates select="@*" />
<!-- File in this Component -->
<xsl:apply-templates select="wix:File" />
<!-- Files in siblings -->
<xsl:apply-templates select="../wix:Component[position()>1]/wix:File" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component[position()>1]/wix:File">
<xsl:copy>
<!-- Removing KeyPath Attr. -->
<xsl:apply-templates select="@*[not(name()='KeyPath')]|node()" />
</xsl:copy>
</xsl:template>
<!-- Removing ComponentRef -->
<xsl:template match="wix:ComponentRef[key('kRemoveComps', @Id)]" />
</xsl:stylesheet>