2013-03-09 2 views
5

xml変換を適用してheat.exeによって生成されたwxsファイルをクリーンアップしようとしています。wxsファイルから望ましくないノードをxsltのトランスクリプトを適用して削除する

以下は、heat.exeのファイル出力例です。

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
      <DirectoryRef Id="APPFOLDER"> 
       <Component Id="cmp78E9FF58917B1844F3E9315A285F3147" Guid="SOME-GUID"> 
        <File Id="fil093D6D7CB723B5B62730D7B4E575F154" KeyPath="yes" Source="PQR.Some.dll" /> 
       </Component> 
       <Component Id="cmp0B084126FAE7577FD84DB29766AC6C2B" Guid="SOME-GUID"> 
        <File Id="filB20C8708D7EB02EDFBCC4D70F9FE7F8A" KeyPath="yes" Source="ABC.Another.dll" /> 
       </Component> 
       <Component Id="cmp83BB1954DECD7D949AAE4ACA68806EC3" Guid="SOME-GUID"> 
        <File Id="fil0E29FBFF7DB39F307A2EE19237A0A579" KeyPath="yes" Source="ABC.OneMore.dll" /> 
       </Component> 
      </DirectoryRef> 
     </Fragment> 
     <Fragment> 
      <ComponentGroup Id="AppFiles"> 
       <ComponentRef Id="cmp78E9FF58917B1844F3E9315A285F3147" /> 
       <ComponentRef Id="cmp0B084126FAE7577FD84DB29766AC6C2B" /> 
       <ComponentRef Id="cmp83BB1954DECD7D949AAE4ACA68806EC3" /> 
      </ComponentGroup> 
     </Fragment> 
    </Wix> 

文字列「ABC」を含むソース属性を持つ子ファイルノードを持つコンポーネントノードを削除したいと考えています。正しいマッチングパターンを使ってそのようなノードを見つける方法を知っています。 コンポーネントノードを削除する前に、コンポーネントのIDを保存して、これを使用して、これまでに記録したIDを持つComponentRefノードを削除する必要があります。

XML変換でこれを達成できる方法はありますか?私は、私が削除するコンポーネントノードのIDを格納するために 'X'と言う変数を作成し、削除するComponentRefノードを見つけるために 'X'を使うことができるものを探しています。

答えて

11

変数なしでこれを行うことができます。このように:あなたのサンプル入力に

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:wi="http://schemas.microsoft.com/wix/2006/wi"> 
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> 
    <xsl:strip-space elements="*"/> 
    <xsl:key name="kCompsToRemove" 
      match="wi:Component[contains(wi:File/@Source, 'ABC')]" 
      use="@Id" /> 

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

    <xsl:template match="*[self::wi:Component or self::wi:ComponentRef] 
         [key('kCompsToRemove', @Id)]" /> 
</xsl:stylesheet> 

を実行すると、これは生産:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
    <DirectoryRef Id="APPFOLDER"> 
     <Component Id="cmp78E9FF58917B1844F3E9315A285F3147" Guid="SOME-GUID"> 
     <File Id="fil093D6D7CB723B5B62730D7B4E575F154" KeyPath="yes" Source="PQR.Some.dll" /> 
     </Component> 
    </DirectoryRef> 
    </Fragment> 
    <Fragment> 
    <ComponentGroup Id="AppFiles"> 
     <ComponentRef Id="cmp78E9FF58917B1844F3E9315A285F3147" /> 
    </ComponentGroup> 
    </Fragment> 
</Wix> 
+0

この1つは魅力のように働きました。すごい@JLRishe。 – vaibinewbee

+0

これはちょうど素晴らしいです、すぐに動作します。ありがとう – sttaq

+1

複数の要素を削除する場合は、一致属性に条件を追加してください: '' – HenningJ

関連する問題