2017-08-22 32 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

我已经编辑了一些建议我的答案 –