2014-02-24 99 views
0

使用Wix Toolset(版本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属性ComponentRef?

<?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> 

回答

1

将以下模板添加到样式表中。如果Directory元素的属性Name对应于“doc”和Id属性相同,则匹配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> 
-3

谢谢你,这是非常有益的

最终的解决方案包括双斜杠来处理与子文件夹的doc文件夹中。

<xsl:template match="wix:ComponentRef[@Id = //wix:Directory[@Name='doc']//wix:Component/@Id]"/ 
+1

@ user2936494:我看到您已将我的解决方案复制到另一个答案。这对Stackoverflow不是很有帮助。相反,请留下评论我的答案,并接受它(标记在左边的勾号),如果它解决了你的问题。 –