使用XSLT转换Heat生成的.wxs(添加RegistryValue并编辑一些值) [英] Transform Heat generated .wxs with XSLT (add RegistryValue and edit some values)

查看:85
本文介绍了使用XSLT转换Heat生成的.wxs(添加RegistryValue并编辑一些值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要的输出:

<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文件:

This is my XSLT file:

<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的输出:

And this is my output using that 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中的文件更改不会应用,例如添加前缀,将密钥路径更改为no,如果我删除了添加注册表的文件,则文件更改会像超级按钮一样工作!

The File changes that are in XSL are not applied like add a prefix, change keypath to no, if i remove the one that adds the registry the file changes work like a charm!

我做错了什么?

感谢您的帮助.

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

UPDATE: Here is original sample of XML without transform:

    <?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>

推荐答案

您说的是:

我一激活

<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,如果我删除了添加注册表的那个 文件更改就像魅力一样发挥作用!

The File changes that are in XSL are not applied like add a prefix, change keypath to no, if i remove the one that adds the registry the file changes work like a charm!

通过激活",我假设您的意思是将其添加到XSLT文件.将 添加到其余转换中后,您将创建一个模糊的规则匹配情况,该情况会引发警告,例如撒克逊人会说:

By "activate", I assume that you mean add it to the XSLT file. When it is added to the rest of the transforms, you create an ambiguous rule match situation that should elicit a warning such as what Saxon would say:

 [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>

这篇关于使用XSLT转换Heat生成的.wxs(添加RegistryValue并编辑一些值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆