2017-08-22 72 views
0

我使用wix工具集的heat.exe實用程序在我的文件夾中生成wxs文件。現在我需要更新生成的wxs文件我的值形式xslt文件。從xslt文件更新wxs文件

生成WXS文件

輸入XML:

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
     <DirectoryRef Id="RFolder"> 
      <Directory Id="dir8A1C71C28CB2FBCD880BDF1115CE4C9E" Name="de" /> 
      <Directory Id="dir75CE436C7AA3432555A9E4DF401C2182" Name="ea" /> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <ComponentGroup Id="RComponents"> 
      <Component Id="cmp85BD6E6D48A917B8EC794CCCAC0E01D3" Directory="dir1149222D61DE053C3631D19DB46C305B" Guid="10339506-F2E3-40EF-82AA-4F21CE23DE2B"> 

       <File Id="fil2A0EE991AFD039C2716E112172877836" KeyPath="yes" Source="$(var.RFolderVar)\ea\doc.ini" /> 
      </Component> 
      <Component Id="cmp318CD297C8EB9EF822C05002107F6F5D" Directory="dir0424E347D4FE768AB1DDE05B6A26D9F9" Guid="6CC9AB04-D367-4E85-9174-A6776968F7EB"> 

       <File Id="filF51143C322B265B0A2E0732F68A10D58" KeyPath="yes" Source="$(var.RFolderVar)\de\set.ini" /> 
      </Component> 
     </ComponentGroup> 
    </Fragment> 
    <Fragment> 
     <DirectoryRef Id="dir8A1C71C28CB2FBCD880BDF1115CE4C9E"> 
      <Directory Id="dir0424E347D4FE768AB1DDE05B6A26D9F9" Name="system" /> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <DirectoryRef Id="dir75CE436C7AA3432555A9E4DF401C2182"> 
      <Directory Id="dir1149222D61DE053C3631D19DB46C305B" Name="Runner" /> 
     </DirectoryRef> 
    </Fragment> 
</Wix> 

我輸入XSLT文件,當我做什麼,可以在計算機上安裝生成條件

輸入XSLT:

<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="wix:Wix"> 
      <xsl:copy> 
       <xsl:apply-templates select="@*" /> 
       <xsl:apply-templates /> 
      </xsl:copy> 
      </xsl:template> 

    <xsl:template match="wix:Component"> 

     <!-- Just copy the tag itself --> 
     <xsl:copy> 

      <xsl:variable name="fvsys" > 
      <xsl:value-of select="*[local-name()='File']/@Source"/> 
      </xsl:variable> 


      <!-- Copy all attributes --> 
      <xsl:apply-templates select="@*" /> 
      <!--<xsl:attribute name="Name">RecoveryMedia</xsl:attribute>--> 
      <!-- This will mark all files in the WebConfig folder as permanent --> 
      <xsl:choose> 
      <!-- Note that the string is translated to all lower case, so you don't have to care about being case sensitive or not --> 
      <xsl:when test="contains($fvsys, 'ea\')"> 
       <!-- Here we will add the Permanent-attribute to this very special component --> 
       <xsl:element name="Condition" namespace="http://schemas.microsoft.com/wix/2006/wi"> 
       <xsl:text disable-output-escaping="yes">&lt;![CDATA[INSTALLATION_LANGUAGE_PACK=&quot;ea&quot;]]&gt;</xsl:text> 
       </xsl:element> 
      </xsl:when> 
      </xsl:choose> 

      <xsl:choose> 
      <xsl:when test="contains($fvsys, 'de\')"> 

       <xsl:element name="Condition" namespace="http://schemas.microsoft.com/wix/2006/wi"> 
       <xsl:text disable-output-escaping="yes">&lt;![CDATA[INSTALLATION_LANGUAGE_PACK=&quot;de&quot;]]&gt;</xsl:text> 
       </xsl:element> 
      </xsl:when> 
      </xsl:choose> 

      <!-- Now take the rest of the inner tag --> 
      <xsl:apply-templates select="node()" /> 
     </xsl:copy> 

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

    </xsl:stylesheet> 

實際結果:

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
     <DirectoryRef Id="RFolder"> 
      <Directory Id="dir8A1C71C28CB2FBCD880BDF1115CE4C9E" Name="de" /> 
      <Directory Id="dir75CE436C7AA3432555A9E4DF401C2182" Name="ea" /> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <ComponentGroup Id="RComponents"> 
      <Component Id="cmp85BD6E6D48A917B8EC794CCCAC0E01D3" Directory="dir1149222D61DE053C3631D19DB46C305B" Guid="10339506-F2E3-40EF-82AA-4F21CE23DE2B"> 
       <Condition><![CDATA[INSTALLATION_LANGUAGE_PACK="ea"]]></Condition> 
       <File Id="fil2A0EE991AFD039C2716E112172877836" KeyPath="yes" Source="$(var.RFolderVar)\ea\doc.ini" /> 
      </Component> 
      <Component Id="cmp318CD297C8EB9EF822C05002107F6F5D" Directory="dir0424E347D4FE768AB1DDE05B6A26D9F9" Guid="6CC9AB04-D367-4E85-9174-A6776968F7EB"> 
       <Condition><![CDATA[INSTALLATION_LANGUAGE_PACK="de"]]></Condition> 
       <File Id="filF51143C322B265B0A2E0732F68A10D58" KeyPath="yes" Source="$(var.RFolderVar)\de\set.ini" /> 
      </Component> 
     </ComponentGroup> 
    </Fragment> 
    <Fragment> 
     <DirectoryRef Id="dir8A1C71C28CB2FBCD880BDF1115CE4C9E"> 
      <Directory Id="dir0424E347D4FE768AB1DDE05B6A26D9F9" Name="system" /> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <DirectoryRef Id="dir75CE436C7AA3432555A9E4DF401C2182"> 
      <Directory Id="dir1149222D61DE053C3631D19DB46C305B" Name="Runner" /> 
     </DirectoryRef> 
    </Fragment> 
</Wix> 

預期結果:

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
     <DirectoryRef Id="RFolder"> 
      <Directory Id="dir8A1C71C28CB2FBCD880BDF1115CE4C9E" Name="de" /> 
      <Directory Id="dir75CE436C7AA3432555A9E4DF401C2182" Name="ea" /> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <ComponentGroup Id="RComponents"> 
      <Component Id="cmp85BD6E6D48A917B8EC794CCCAC0E01D3" Directory="dir1149222D61DE053C3631D19DB46C305B" Guid="10339506-F2E3-40EF-82AA-4F21CE23DE2B"> 
       <Condition><![CDATA[INSTALLATION_LANGUAGE_PACK="ea"]]></Condition> 
       <File Id="fil2A0EE991AFD039C2716E112172877836" KeyPath="yes" Source="$(var.RFolderVar)\ea\doc.ini" /> 
      </Component> 
      <Component Id="cmp318CD297C8EB9EF822C05002107F6F5D" Directory="dir0424E347D4FE768AB1DDE05B6A26D9F9" Guid="6CC9AB04-D367-4E85-9174-A6776968F7EB"> 
       <Condition><![CDATA[INSTALLATION_LANGUAGE_PACK="de"]]></Condition> 
       <File Id="filF51143C322B265B0A2E0732F68A10D58" KeyPath="yes" Source="$(var.RFolderVar)\de\set.ini" /> 
      </Component> 
     </ComponentGroup> 
    </Fragment> 
    <Fragment> 
     <DirectoryRef Id="RFolder"> 
      <Directory Id="dir0424E347D4FE768AB1DDE05B6A26D9F9" Name="system" /> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <DirectoryRef Id="RFolder"> 
      <Directory Id="dir1149222D61DE053C3631D19DB46C305B" Name="Runner" /> 
     </DirectoryRef> 
    </Fragment> 
</Wix> 

我不知道如何改變從ROOL DirectoryRef新的價值的所有標識的...也許有人能幫助我嗎?

回答

0

我不是100%確定的邏輯,但是第一次嘗試添加xsl:key樣式表

<xsl:key name="Directories" match="wix:Directory" use="@Id" /> 

然後將下面的模板匹配,匹配DirectoryRef有一個id是存在Directory元素。

<xsl:template match="wix:DirectoryRef/@Id[key('Directories', .)]"> 
    <xsl:attribute name="Id"> 
     <xsl:value-of select="key('Directories', .)/../@Id" /> 
    </xsl:attribute> 
</xsl:template> 

http://xsltransform.net/bEzjRKs

編輯看到它在行動:在回答你的評論,我不太清楚你的意思是「覆蓋標識在DirectoryRef其上目錄的編號的鏈接在第一DirectroyRef這個<DirectoryRef Id="RFolder"> ,但嘗試更新xsl:key到以下內容之一:

<xsl:key name="Directories" match="wix:DirectoryRef[@Id='RFolder']/wix:Directory" use="@Id" /> 

<xsl:key name="Directories" match="wix:Fragment[1]/wix:DirectoryRef/wix:Directory" use="@Id" /> 

<xsl:key name="Directories" match="wix:DirectoryRef[not(preceding::wix:DirectoryRef)]/wix:Directory" use="@Id" /> 
+0

非常接近的人,但不是我想要的東西。如果我使用此代碼,我得到覆蓋所有標識的,但我想改寫標識在DirectoryRef其上的目錄鏈接。 ID' s在第一個DirectroyRef這個'' – teror4uks

+0

我已經編輯了一些建議我的答案 –