2011-02-07 40 views
0

我正在構建基於一組自動生成的XML文件的Wix安裝程序(我使用HEAT來收集文件夾內容)。我需要從生成的XML排除某些文件,例如,從這個片段我要排除一個文件的「web.config」:如何使用XSL基於子級的屬性排除父元素?

<Component Id="cmp87E809324190AF5E85315B10C397DB8F" 
      Directory="Content" 
      Guid="{4210C091-E16F-45EA-9005-A7487CF6AC69}"> 
    <File Id="fil13DABBB8A7FACF8E81FE69FD2464DE48" 
     Source="$(var.ProjectDir)\MyService.svc" /> 
</Component> 
<Component Id="cmp276C007DCB38D3C2E4DA41DFDD8F5CED" 
      Directory="Content" 
      Guid="{A01BE50E-3B00-40EF-96EB-D48AED1F6259}"> 
    <File Id="fil527A2DD913A88F35BD2B90F10029FB32" 
     Source="$(var.ProjectDir)\Web.config" /> 
</Component> 

我申請以下轉變:

<!-- Identity template --> 
    <xsl:template match="@* | node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* | node()" /> 
    </xsl:copy> 
    </xsl:template> 

    <!-- exclude files --> 
    <xsl:template match="wix:Component/wix:File[ 
          @Source='$(var.ProjectDir)\Web.config' 
         ]"> 
    </xsl:template> 

不幸它只刪除「File」元素(它匹配的那個),我想刪除匹配的「File」子元素的父元素(「Component」)。這在XSLT中必須相對容易,但我還沒有弄明白。

在此先感謝

回答

2

你應該使用:

<!-- exclude files --> 
<xsl:template match=" 
     Component[File/@Source='$(var.ProjectDir)\Web.config']"/> 

命名空間中的示例XML丟失,所以你可以自行添加。

+0

賓果!非常感謝。 – 2011-02-07 10:17:27

相關問題