【问题标题】:Transform Heat generated .wxs with XSLT (add RegistryValue and edit some values)使用 XSLT 转换 Heat 生成的 .wxs(添加 RegistryValue 并编辑一些值)
【发布时间】:2013-10-27 10:00:27
【问题描述】:

这是我想要的输出:

<Component Id="C_SOMEFILE" Guid="some-guid-here">
    <File Id="File_SOMEFILE" Source="$(var.Source)\SOMEFILE" KeyPath="no" />
    <RegistryValue Root="HKCU" Key="Software\Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>

这是我的 XSLT 文件:

<xsl:stylesheet version="1.0" 
                            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                            xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
                            xmlns="http://schemas.microsoft.com/wix/2006/wi"
                            exclude-result-prefixes="xsl wix">

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

<xsl:strip-space elements="*"/>

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

<!--Set KeyPath to NO-->
<xsl:template match='wix:File[@Id]'>
    <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <xsl:attribute name="KeyPath">
            <xsl:text>no</xsl:text>
        </xsl:attribute>
    </xsl:copy>
</xsl:template>

<xsl:template match="wix:Component/wix:File">
    <xsl:copy-of select="." />
    <RegistryValue Root="HKCU" Key="Software\Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</xsl:template>

<!--Give Compoentent ID prefix C_-->
<xsl:template match="wix:Component/@Id">
    <xsl:attribute name="{name()}">
        <xsl:value-of select="concat('C_', .)" />
    </xsl:attribute>
</xsl:template>

<!--Give Componentref ID prefix C_-->
<xsl:template match="wix:ComponentRef/@Id">
    <xsl:attribute name="{name()}">
        <xsl:value-of select="concat('C_', .)" />
    </xsl:attribute>
</xsl:template>

<!--Give Directory ID prefix Dir_-->
<xsl:template match="wix:Directory/@Id">
    <xsl:attribute name="{name()}">
        <xsl:value-of select="concat('Dir_', .)" />
    </xsl:attribute>
</xsl:template>

<!--Give File ID prefix File_-->
<xsl:template match="wix:File/@Id">
    <xsl:attribute name="{name()}">
        <xsl:value-of select="concat('File_', .)" />
    </xsl:attribute>
</xsl:template>

这是我使用该 XSL 的输出:

<Component Id="C_SOMEFILE" Guid="some-guid-here">
    <File Id="SOMEFILE" KeyPath="yes" Source="$(var.Source)\SOMEFILE" />
    <RegistryValue Root="HKCU" Key="Software\Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>

一旦激活

<xsl:template match="wix:Component/wix:File">
   <xsl:copy-of select="." />
   <RegistryValue Root="HKCU" Key="Software\Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</xsl:template>

XSL 中的文件更改不会像添加前缀一样应用,将 keypath 更改为 no,如果我删除添加注册表的文件更改就像一个魅力!

我做错了什么?

感谢任何帮助,谢谢。

更新:这是未经转换的 XML 原始示例:

    <?xml version="1.0" encoding="utf-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
       <Fragment>
          <DirectoryRef Id="Dir_Exentsions">
              <Directory Id="SOMEFILE" Name="SOMEFILE">
                 <Component Id="SOMEFILE" Guid="7D8FDF2D-CED9-4A08-A57E-96CD7FFA8E9A">
                    <File Id="SOMEFILE" KeyPath="yes" Source="$(var.Source)\SOMEFILE" />
                 </Component>          
              </Directory>
          </DirectoryRef>
       </Fragment>
     </Wix>

【问题讨论】:

    标签: xml xslt wix heat


    【解决方案1】:

    你说:

    一旦激活

    <xsl:template match="wix:Component/wix:File">
       <xsl:copy-of select="." />
       <RegistryValue Root="HKCU" Key="Software\Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
    </xsl:template>
    

    XSL 中的文件更改不会像添加前缀那样应用, 将 keypath 更改为 no,如果我删除添加注册表的那个 文件更改就像一个魅力!

    “激活”是指将其添加到 XSLT 文件。当它添加到其余的转换中时,您会创建一个模糊规则匹配情况,它应该会引发一个警告,例如撒克逊人会说的话:

     [xslt] : Error! Ambiguous rule match for /Wix/Fragment[1]/DirectoryRef[1]/Directory[1]/Component[1]/File[1]
     [xslt] Matches both "wix:Component/wix:File" on line 28 of file:/c:/gd/usr/kjh/proj/try/xslt/try.xsl
     [xslt] and "wix:File[@Id]" on line 19 of file:/c:/gd/usr/kjh/proj/try/xslt/try.xsl
    

    以下是歧义的解决方案:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" 
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
                    xmlns="http://schemas.microsoft.com/wix/2006/wi"
                    exclude-result-prefixes="xsl wix">
    
      <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
      <xsl:strip-space elements="*"/>
    
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="wix:Component/wix:File[@Id]">
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:attribute name="KeyPath">
            <xsl:text>no</xsl:text>
          </xsl:attribute>
        </xsl:copy>
        <RegistryValue Root="HKCU" Key="Software\Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </xsl:template>
    
      <xsl:template match="wix:Component/wix:File[not(@Id)]">
        <!-- Placeholder for handling anything that should happen
             different for wix:File without @Id attribute.  -->
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
        </xsl:copy>
      </xsl:template>
    
      <!--Give Compoentent ID prefix C_-->
      <xsl:template match="wix:Component/@Id">
        <xsl:attribute name="{name()}">
          <xsl:value-of select="concat('C_', .)" />
        </xsl:attribute>
      </xsl:template>
    
      <!--Give Componentref ID prefix C_-->
      <xsl:template match="wix:ComponentRef/@Id">
        <xsl:attribute name="{name()}">
          <xsl:value-of select="concat('C_', .)" />
        </xsl:attribute>
      </xsl:template>
    
      <!--Give Directory ID prefix Dir_-->
      <xsl:template match="wix:Directory/@Id">
        <xsl:attribute name="{name()}">
          <xsl:value-of select="concat('Dir_', .)" />
        </xsl:attribute>
      </xsl:template>
    
      <!--Give File ID prefix File_-->
      <xsl:template match="wix:File/@Id">
        <xsl:attribute name="{name()}">
          <xsl:value-of select="concat('File_', .)" />
        </xsl:attribute>
      </xsl:template>
    </xsl:stylesheet>
    

    在您的输入文件上运行时,会产生所需的输出:

    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
       <Fragment>
          <DirectoryRef Id="Dir_Exentsions">
             <Directory Id="Dir_SOMEFILE" Name="SOMEFILE">
                <Component Id="C_SOMEFILE" Guid="7D8FDF2D-CED9-4A08-A57E-96CD7FFA8E9A">
                   <File Id="File_SOMEFILE" KeyPath="no" Source="$(var.Source)\SOMEFILE"/>
                   <RegistryValue Root="HKCU"
                                  Key="Software\Product"
                                  Name="installed"
                                  Type="integer"
                                  Value="1"
                                  KeyPath="yes"/>
                </Component>
             </Directory>
          </DirectoryRef>
       </Fragment>
    </Wix>
    

    【讨论】:

    • 这是完美的,它就像一个魅力。也感谢您提到“撒克逊人”。
    猜你喜欢
    • 2015-10-12
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 2020-02-11
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    相关资源
    最近更新 更多