1

我有一些文件需要根据给定的环境输入(如 dev、prod)从 .WXS 中删除,这些文件将作为属性传递给 Heat.exe。基于此,我需要在通过 XSLT 转换收获后从 Fragment.WXS 中过滤或删除一些文件。例如,如果 xslt 模板用于开发,那么我需要源文件不包含 .UAT,.Prod,.Test 的所有文件。我还需要使用 Heat 执行转换的命令。

请参阅下面来自热生成输出的一些组件

           <?xml version="1.0" encoding="utf-8"?>
            <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
                <Fragment>
                    <DirectoryRef Id="TARGETDIR">
                       <Directory Id="dir8EF11DA0EAFBFCB7A0B81343D3750C8B" Name="SCBUDirect" />
                    </DirectoryRef>
                </Fragment>
                <Fragment>
        <ComponentGroup Id="SCBUDirect">

        <Component Id="cmpE3B75974B57E1263C93B9B05FDFE715F" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{CA810124-F44B-4EF5-986A-07FAA67434AB}">
        <File Id="fil85729F855FDD131D6161043C08CB4543" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\TestBuild_dev_ConnectionStrings.config" />
        </Component>

        <Component Id="cmpERG5974B57E1263C93B9B05FDFE715F" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{ERGT50124-F44B-4EF5-986A-07FAA67434AB}">
            <File Id="fil8574324425555FDD131D6161043C08CB4543" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\TestBuild_prod_ConnectionStrings.config" />
         </Component>

<Component Id="cmp51A6C4030B563BC4A64DA99AED42D978" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{CF063EF0-6926-4D21-B89D-BD71E0E926F7}">
                <File Id="fil1494493122AA1F38F8D2C11F93A8D4E8" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment.config" />
            </Component>


        <Component Id="cmpDF354EF7DC6C98108D05886911231011" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{F912A8C7-1226-49D6-897F-1878A1607B16}">
        <File Id="fil1058EF5A5E46590311096FFC704CD243" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.dev" />
        </Component>

        <Component Id="cmpD84FEB6CD3B1AE3534AA6B94CF5065C8" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{8BEBA112-9967-4DD9-96FC-25A879C5D6FA}">
        <File Id="filE0D63A4EC6CCCF6E9C06A91E04EA87E7" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.prod" />
        </Component>

        <Component Id="cmp0B6A1EF1380A825CC1F3894FAA38CC0B" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{60C807BD-142C-4C1F-8366-DC297657AB0A}">
        <File Id="fil20F28B0827462F414C432783951DD049" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.test" />
        </Component>

        <Component Id="cmp80CFA73AA353BE789D4539008E7F3516" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{0B3FA0E7-8F66-408C-944F-DAA0A847B6C4}">
        <File Id="fil2B292A388045FDF49475C9F6C5D144D1" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.uat" />
        </Component>

     <Component Id="cmpE1C2EEC551696DCE99C2CAB9ED013C54" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{A3D766EE-A488-468A-A7BF-DDB507B21299}">
                    <File Id="fil2F90622E603C0AF703A504C3DE3A6201" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.config" />
                </Component>
                <Component Id="cmpEBF2150BC59E378124B87AF387DA5519" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{16CF5D16-A551-4184-9E9D-772A9277941A}">
                    <File Id="fil9241DCC3F781240AD979AAF25BF020F5" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.CSR.config" />
                </Component>
                <Component Id="cmpA8F307EAB3BEB1352C23666A8E11D981" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{3A42EC95-3DE5-4BB8-870F-E4AE8C8B1AE0}">
                    <File Id="fil8A99AE4CB701995838FD078019546D30" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Prod.config.xml" />
                </Component>
                <Component Id="cmpB64314E8A44B127FAE8A6CBAAF9AA052" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{450B216D-7A3D-40EF-A41D-AAB2FA65BC5D}">
                    <File Id="fil0F1FCF642AF4B0D8A101964BCAFCA227" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Prod.CSR.config.xml" />
                </Component>
                <Component Id="cmpD59E44F90B1003A9D3FEEE194F8AA63D" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{94AA1663-5043-4DA1-A60D-50FFEDED6B7A}">
                    <File Id="filCA238418D1A725B1303D44003BEE495E" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Test.config.xml" />
                </Component>
                <Component Id="cmp1AF2C8707EBD76A179C1CE20515E0A9B" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{42342DFE-227C-4F70-B2E9-B9422DEA45AE}">
                    <File Id="filAB15496223BAA05CC1CCFED05F52E902" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Test.CSR.config.xml" />
                </Component>
                <Component Id="cmp89433C61AF95511BE1BC8121DAAAA401" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{DDB6E815-9946-4744-8D1A-E4BE3D09EC2E}">
                    <File Id="filC0041C051A21C3705C9417015F51ACCC" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.UAT.config.xml" />
                </Component>

                <Component Id="cmp131FA57DB66446A7226E0236B8ACAAFD" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{6CA4CE62-33FD-4BF9-8E43-1A079983D492}">
                    <File Id="fil42A0BC81342E575F8EA9F004A065CCA4" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.UAT.CSR.config.xml" />
                </Component>
     <Component Id="cmp3B36FD232E0AAD653B9259D5F2AC60A2" Directory="dirE4970414C520BB64F468385DC180508F" Guid="{BF4A808E-AFBD-4F43-8F90-20E38639C8BD}">
                    <File Id="filFD59C7E39C8BCA47D7ECEA7EBCA4E8FF" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\controls\ReferAFriend\ReferAFriendInfo.ascx" />
                </Component>

        </ComponentGroup>
        </Fragment>

                <Fragment>
                    <DirectoryRef Id="dir19836A556979704BCD883A1A4BC5ACCA">
                       <Directory Id="dir64C5FB989D956FBA878D608B754DE28A" Name="App_Config" />
                    </DirectoryRef>
                </Fragment> 
               <Fragment>
            <DirectoryRef Id="dir64C5FB989D956FBA878D608B754DE28A">
                <Directory Id="dir83BD7C94126520DBEDF76AF461521286" Name="Deployment" />
            </DirectoryRef>
              </Fragment>
     <Fragment>
            <DirectoryRef Id="dir0370A1E873AC03CA5FA01FB090FBCEF4">
                <Directory Id="dirE4970414C520BB64F468385DC180508F" Name="ReferAFriend" />
            </DirectoryRef>
        </Fragment>    
            </Wix>

这是我的 xslt 文件提出的需要使其工作的内容。

   ?xml version="1.0" encoding="UTF-8"?>
        <xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns="http://schemas.microsoft.com/wix/2006/wi"
            xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
            xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

          <xsl:output method="xml" indent="yes"/>

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

          <!--<!–Set up keys for ignoring various file types–&gt;-->
          <xsl:key name="config-search" match="wix:Component[contains(wix:File/@Source, 'TestBuild_prod')]" use="@Id"/>
          <!--<!–Match and ignore TestBuild_prod files for dev Environment similarly vice-versa for prod Environment –&gt;-->
          <xsl:template match="wix:Component[key('config-search', @Id)]"/>
          <xsl:template match="wix:ComponentRef[key('config-search', @Id)]"/>

        </xsl:stylesheet>

如果输入为“dev”,则在转换后,fragment.WXS 文件如下所示

      <?xml version="1.0" encoding="utf-8"?>
            <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
                <Fragment>
                    <DirectoryRef Id="TARGETDIR">
                       <Directory Id="dir8EF11DA0EAFBFCB7A0B81343D3750C8B" Name="SCBUDirect" />
                    </DirectoryRef>
                </Fragment>

        <Fragment>
        <ComponentGroup Id="SCBUDirect">

        <Component Id="cmpE3B75974B57E1263C93B9B05FDFE715F" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{CA810124-F44B-4EF5-986A-07FAA67434AB}">
        <File Id="fil85729F855FDD131D6161043C08CB4543" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\TestBuild_dev_ConnectionStrings.config" />
        </Component>


       <Component Id="cmp51A6C4030B563BC4A64DA99AED42D978" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{CF063EF0-6926-4D21-B89D-BD71E0E926F7}">
            <File Id="fil1494493122AA1F38F8D2C11F93A8D4E8" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment.config" />
        </Component>


        <Component Id="cmpDF354EF7DC6C98108D05886911231011" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{F912A8C7-1226-49D6-897F-1878A1607B16}">
        <File Id="fil1058EF5A5E46590311096FFC704CD243" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.dev" />
        </Component>

        <Component Id="cmpE1C2EEC551696DCE99C2CAB9ED013C54" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{A3D766EE-A488-468A-A7BF-DDB507B21299}">
                <File Id="fil2F90622E603C0AF703A504C3DE3A6201" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.config" />
        </Component>

        <Component Id="cmpEBF2150BC59E378124B87AF387DA5519" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{16CF5D16-A551-4184-9E9D-772A9277941A}">
                <File Id="fil9241DCC3F781240AD979AAF25BF020F5" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.CSR.config" />
       </Component>

     <Component Id="cmp3B36FD232E0AAD653B9259D5F2AC60A2" Directory="dirE4970414C520BB64F468385DC180508F" Guid="{BF4A808E-AFBD-4F43-8F90-20E38639C8BD}">
                <File Id="filFD59C7E39C8BCA47D7ECEA7EBCA4E8FF" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\controls\ReferAFriend\ReferAFriendInfo.ascx" />
     </Component>

    </ComponentGroup>
    </Fragment>
                <Fragment>
                    <DirectoryRef Id="dir19836A556979704BCD883A1A4BC5ACCA">
                   <Directory Id="dir64C5FB989D956FBA878D608B754DE28A" Name="App_Config" />
                    </DirectoryRef>
                </Fragment>     
               <Fragment>
        <DirectoryRef Id="dir64C5FB989D956FBA878D608B754DE28A">
            <Directory Id="dir83BD7C94126520DBEDF76AF461521286" Name="Deployment" />
        </DirectoryRef>
             </Fragment> 
 <Fragment>
        <DirectoryRef Id="dir0370A1E873AC03CA5FA01FB090FBCEF4">
            <Directory Id="dirE4970414C520BB64F468385DC180508F" Name="ReferAFriend" />
        </DirectoryRef>
    </Fragment> 
 </Wix>
4

2 回答 2

2

这似乎可以满足您的要求。有一个xsl:param默认值为dev. 您可以对其进行修改以控制Component保留哪些元素。

XML 输入

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="TARGETDIR">
            <Directory Id="dir8EF11DA0EAFBFCB7A0B81343D3750C8B" Name="SCBUDirect" />
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="SCBUDirect">

            <Component Id="cmpE3B75974B57E1263C93B9B05FDFE715F" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{CA810124-F44B-4EF5-986A-07FAA67434AB}">
                <File Id="fil85729F855FDD131D6161043C08CB4543" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\TestBuild_dev_ConnectionStrings.config" />
            </Component>

            <Component Id="cmpERG5974B57E1263C93B9B05FDFE715F" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{ERGT50124-F44B-4EF5-986A-07FAA67434AB}">
                <File Id="fil8574324425555FDD131D6161043C08CB4543" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\TestBuild_prod_ConnectionStrings.config" />
            </Component>

            <Component Id="cmp51A6C4030B563BC4A64DA99AED42D978" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{CF063EF0-6926-4D21-B89D-BD71E0E926F7}">
                <File Id="fil1494493122AA1F38F8D2C11F93A8D4E8" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment.config" />
            </Component>


            <Component Id="cmpDF354EF7DC6C98108D05886911231011" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{F912A8C7-1226-49D6-897F-1878A1607B16}">
                <File Id="fil1058EF5A5E46590311096FFC704CD243" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.dev" />
            </Component>

            <Component Id="cmpD84FEB6CD3B1AE3534AA6B94CF5065C8" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{8BEBA112-9967-4DD9-96FC-25A879C5D6FA}">
                <File Id="filE0D63A4EC6CCCF6E9C06A91E04EA87E7" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.prod" />
            </Component>

            <Component Id="cmp0B6A1EF1380A825CC1F3894FAA38CC0B" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{60C807BD-142C-4C1F-8366-DC297657AB0A}">
                <File Id="fil20F28B0827462F414C432783951DD049" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.test" />
            </Component>

            <Component Id="cmp80CFA73AA353BE789D4539008E7F3516" Directory="dir64C5FB989D956FBA878D608B754DE28A" Guid="{0B3FA0E7-8F66-408C-944F-DAA0A847B6C4}">
                <File Id="fil2B292A388045FDF49475C9F6C5D144D1" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.uat" />
            </Component>

            <Component Id="cmpE1C2EEC551696DCE99C2CAB9ED013C54" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{A3D766EE-A488-468A-A7BF-DDB507B21299}">
                <File Id="fil2F90622E603C0AF703A504C3DE3A6201" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.config" />
            </Component>
            <Component Id="cmpEBF2150BC59E378124B87AF387DA5519" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{16CF5D16-A551-4184-9E9D-772A9277941A}">
                <File Id="fil9241DCC3F781240AD979AAF25BF020F5" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.CSR.config" />
            </Component>
            <Component Id="cmpA8F307EAB3BEB1352C23666A8E11D981" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{3A42EC95-3DE5-4BB8-870F-E4AE8C8B1AE0}">
                <File Id="fil8A99AE4CB701995838FD078019546D30" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Prod.config.xml" />
            </Component>
            <Component Id="cmpB64314E8A44B127FAE8A6CBAAF9AA052" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{450B216D-7A3D-40EF-A41D-AAB2FA65BC5D}">
                <File Id="fil0F1FCF642AF4B0D8A101964BCAFCA227" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Prod.CSR.config.xml" />
            </Component>
            <Component Id="cmpD59E44F90B1003A9D3FEEE194F8AA63D" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{94AA1663-5043-4DA1-A60D-50FFEDED6B7A}">
                <File Id="filCA238418D1A725B1303D44003BEE495E" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Test.config.xml" />
            </Component>
            <Component Id="cmp1AF2C8707EBD76A179C1CE20515E0A9B" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{42342DFE-227C-4F70-B2E9-B9422DEA45AE}">
                <File Id="filAB15496223BAA05CC1CCFED05F52E902" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Test.CSR.config.xml" />
            </Component>
            <Component Id="cmp89433C61AF95511BE1BC8121DAAAA401" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{DDB6E815-9946-4744-8D1A-E4BE3D09EC2E}">
                <File Id="filC0041C051A21C3705C9417015F51ACCC" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.UAT.config.xml" />
            </Component>

            <Component Id="cmp131FA57DB66446A7226E0236B8ACAAFD" Directory="dir83BD7C94126520DBEDF76AF461521286" Guid="{6CA4CE62-33FD-4BF9-8E43-1A079983D492}">
                <File Id="fil42A0BC81342E575F8EA9F004A065CCA4" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.UAT.CSR.config.xml" />
            </Component>
            <Component Id="cmp3B36FD232E0AAD653B9259D5F2AC60A2" Directory="dirE4970414C520BB64F468385DC180508F" Guid="{BF4A808E-AFBD-4F43-8F90-20E38639C8BD}">
                <File Id="filFD59C7E39C8BCA47D7ECEA7EBCA4E8FF" KeyPath="yes" Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\controls\ReferAFriend\ReferAFriendInfo.ascx" />
            </Component>

        </ComponentGroup>
    </Fragment>

    <Fragment>
        <DirectoryRef Id="dir19836A556979704BCD883A1A4BC5ACCA">
            <Directory Id="dir64C5FB989D956FBA878D608B754DE28A" Name="App_Config" />
        </DirectoryRef>
    </Fragment> 
    <Fragment>
        <DirectoryRef Id="dir64C5FB989D956FBA878D608B754DE28A">
            <Directory Id="dir83BD7C94126520DBEDF76AF461521286" Name="Deployment" />
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <DirectoryRef Id="dir0370A1E873AC03CA5FA01FB090FBCEF4">
            <Directory Id="dirE4970414C520BB64F468385DC180508F" Name="ReferAFriend" />
        </DirectoryRef>
    </Fragment>    
</Wix>

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:wi="http://schemas.microsoft.com/wix/2006/wi" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:param name="type" select="'dev'"/>
    <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
    <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>

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

    <xsl:template match="wi:Component">
        <xsl:choose>
            <xsl:when test="$type='dev'">
                <xsl:variable name="source" select="translate(wi:File/@Source,$upper,$lower)"/>
                <!--Note: These are not exact matches. contains() checks to see if the string is anywhere in $source.-->                
                <!--.test - substring($source,string-length($source) - 4,4)-->
                <xsl:if test="not(contains($source,'.test')) and not(contains($source,'.uat')) and not(contains($source,'.prod'))">
                    <xsl:call-template name="ident"/>
                </xsl:if>               
            </xsl:when>
            <xsl:when test="$type='blah'">
                <!--Copy xsl:if from above and modify for 'blah' types.-->
            </xsl:when>
            <xsl:otherwise>
                <!--If you need to output anything by default, it would go here. Otherwise, xsl:otherwise 
                is not needed and can be removed.-->
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

XML 输出

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
   <Fragment>
      <DirectoryRef Id="TARGETDIR">
         <Directory Id="dir8EF11DA0EAFBFCB7A0B81343D3750C8B" Name="SCBUDirect"/>
      </DirectoryRef>
   </Fragment>
   <Fragment>
      <ComponentGroup Id="SCBUDirect">
         <Component Id="cmpE3B75974B57E1263C93B9B05FDFE715F"
                    Directory="dir64C5FB989D956FBA878D608B754DE28A"
                    Guid="{CA810124-F44B-4EF5-986A-07FAA67434AB}">
            <File Id="fil85729F855FDD131D6161043C08CB4543"
                  KeyPath="yes"
                  Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\TestBuild_dev_ConnectionStrings.config"/>
         </Component>
         <Component Id="cmpERG5974B57E1263C93B9B05FDFE715F"
                    Directory="dir64C5FB989D956FBA878D608B754DE28A"
                    Guid="{ERGT50124-F44B-4EF5-986A-07FAA67434AB}">
            <File Id="fil8574324425555FDD131D6161043C08CB4543"
                  KeyPath="yes"
                  Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\TestBuild_prod_ConnectionStrings.config"/>
         </Component>
         <Component Id="cmp51A6C4030B563BC4A64DA99AED42D978"
                    Directory="dir64C5FB989D956FBA878D608B754DE28A"
                    Guid="{CF063EF0-6926-4D21-B89D-BD71E0E926F7}">
            <File Id="fil1494493122AA1F38F8D2C11F93A8D4E8"
                  KeyPath="yes"
                  Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment.config"/>
         </Component>
         <Component Id="cmpDF354EF7DC6C98108D05886911231011"
                    Directory="dir64C5FB989D956FBA878D608B754DE28A"
                    Guid="{F912A8C7-1226-49D6-897F-1878A1607B16}">
            <File Id="fil1058EF5A5E46590311096FFC704CD243"
                  KeyPath="yes"
                  Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\basic.log4net.dev"/>
         </Component>
         <Component Id="cmpE1C2EEC551696DCE99C2CAB9ED013C54"
                    Directory="dir83BD7C94126520DBEDF76AF461521286"
                    Guid="{A3D766EE-A488-468A-A7BF-DDB507B21299}">
            <File Id="fil2F90622E603C0AF703A504C3DE3A6201"
                  KeyPath="yes"
                  Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.config"/>
         </Component>
         <Component Id="cmpEBF2150BC59E378124B87AF387DA5519"
                    Directory="dir83BD7C94126520DBEDF76AF461521286"
                    Guid="{16CF5D16-A551-4184-9E9D-772A9277941A}">
            <File Id="fil9241DCC3F781240AD979AAF25BF020F5"
                  KeyPath="yes"
                  Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\App_Config\Deployment\Deployment.Dev.CSR.config"/>
         </Component>
         <Component Id="cmp3B36FD232E0AAD653B9259D5F2AC60A2"
                    Directory="dirE4970414C520BB64F468385DC180508F"
                    Guid="{BF4A808E-AFBD-4F43-8F90-20E38639C8BD}">
            <File Id="filFD59C7E39C8BCA47D7ECEA7EBCA4E8FF"
                  KeyPath="yes"
                  Source="C:\Workspaces\Chatra\Website\SCBUDirect.B2CWeb\controls\ReferAFriend\ReferAFriendInfo.ascx"/>
         </Component>
      </ComponentGroup>
   </Fragment>
   <Fragment>
      <DirectoryRef Id="dir19836A556979704BCD883A1A4BC5ACCA">
         <Directory Id="dir64C5FB989D956FBA878D608B754DE28A" Name="App_Config"/>
      </DirectoryRef>
   </Fragment>
   <Fragment>
      <DirectoryRef Id="dir64C5FB989D956FBA878D608B754DE28A">
         <Directory Id="dir83BD7C94126520DBEDF76AF461521286" Name="Deployment"/>
      </DirectoryRef>
   </Fragment>
   <Fragment>
      <DirectoryRef Id="dir0370A1E873AC03CA5FA01FB090FBCEF4">
         <Directory Id="dirE4970414C520BB64F468385DC180508F" Name="ReferAFriend"/>
      </DirectoryRef>
   </Fragment>
</Wix>
于 2013-02-21T16:25:08.160 回答
0

我已经为开发环境提出了以下解决方案,但不确定它是否有效。同样,我需要为“prod”、“uat”和“test”创建 XSLT 模板。但我相信你会提供更好的解决方案。通常所有文件都有其环境的点扩展名。

   <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns="http://schemas.microsoft.com/wix/2006/wi"
        xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

      <xsl:output method="xml" indent="yes"/>
      <xsl:strip-space elements="*"/>

      <xsl:param name="type" select="'dev'"/>
      <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
      <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>


      <!--<!–Identity Transform–&gt;-->
      <xsl:template match="@*|node()" name="ident">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>

      <!--<!–Set up keys for ignoring various file types–&gt;-->
      <xsl:key name="prod" match="wix:Component[contains(wix:File/@Source, 'prod')]" use="@Id"/>
      <!--<!–Match and ignore .prod files–&gt;-->
      <xsl:template match="wix:Component[key('prod', @Id)]"/>
      <xsl:template match="wix:ComponentRef[key('prod', @Id)]"/>

           <!--<!–Set up keys for ignoring various file types–&gt;-->
      <xsl:key name="Prod" match="wix:Component[contains(wix:File/@Source, '.Prod')]" use="@Id"/>
      <!--<!–Match and ignore .Prod files–&gt;-->
      <xsl:template match="wix:Component[key('Prod', @Id)]"/>
      <xsl:template match="wix:ComponentRef[key('Prod', @Id)]"/>

          <!--<!–Set up keys for ignoring various file types–&gt;-->
      <xsl:key name="uat" match="wix:Component[contains(wix:File/@Source, '.uat')]" use="@Id"/>
      <!--<!–Match and ignore .uat files–&gt;-->
      <xsl:template match="wix:Component[key('uat', @Id)]"/>
      <xsl:template match="wix:ComponentRef[key('uat', @Id)]"/>

           <!--<!–Set up keys for ignoring various file types–&gt;-->
      <xsl:key name="UAT" match="wix:Component[contains(wix:File/@Source, '.UAT')]" use="@Id"/>
      <!--<!–Match and ignore .UAT files–&gt;-->
      <xsl:template match="wix:Component[key('UAT', @Id)]"/>
      <xsl:template match="wix:ComponentRef[key('UAT', @Id)]"/>

           <!--<!–Set up keys for ignoring various file types–&gt;-->
      <xsl:key name="Test" match="wix:Component[contains(wix:File/@Source, '.Test')]" use="@Id"/>
      <!--<!–Match and ignore .Test files–&gt;-->
      <xsl:template match="wix:Component[key('Test', @Id)]"/>
      <xsl:template match="wix:ComponentRef[key('Test', @Id)]"/>


               <!--<!–Set up keys for ignoring various file types–&gt;-->
      <xsl:key name="test" match="wix:Component[contains(wix:File/@Source, '.test')]" use="@Id"/>
      <!--<!–Match and ignore .test files–&gt;-->
      <xsl:template match="wix:Component[key('test', @Id)]"/>
      <xsl:template match="wix:ComponentRef[key('test', @Id)]"/>

    </xsl:stylesheet>
于 2013-02-22T20:22:20.830 回答