2014-02-24 97 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不是很有幫助。相反,請留下評論我的答案,並接受它(標記在左邊的勾號),如果它解決了你的問題。 –