使用 XSLT 转换 Heat 生成的 .wxs(添加RegistryValue 并编辑一些值)

2024-03-20

这是我想要的输出:

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

我做错了什么?

感谢任何帮助,谢谢。

UPDATE:这是未经转换的 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>

You say:

我一激活

<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 文件中。当它is添加到其余的转换中,您创建了一个规则匹配情况不明确这应该引起一个警告,例如撒克逊人会说的话:

 [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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 XSLT 转换 Heat 生成的 .wxs(添加RegistryValue 并编辑一些值) 的相关文章

  • XDocument.Save() 删除我的 实体

    我编写了一个工具来使用 C 和 Linq to XML 修复一些 XML 文件 即插入一些缺失的属性 值 该工具将现有 XML 文件加载到 XDocument 对象中 然后 它向下解析节点以插入丢失的数据 之后 它调用 XDocument
  • 使用 PHP 将子项添加到 XML 文件

    添加子项时 抛出此错误 无法添加孩子 父级不是 XML 树的永久成员 我无法解决这个问题 这是我的代码 if visited FIRST xml new SimpleXMLElement
  • 使用 foreach 循环和 XmlNodeList C# 将新节点附加到节点列表

    目前我处理的是这样的XML类型 XML FILE http 20drive google com open id 0By5BxgNi9eGcRldxcEZNU0FDTzQ 参考XML文件 我想检查一个节点 如果找不到该节点 我必须将该节点附
  • 从 XML 构建树结构的速度很慢

    我正在将 XML 文档解析为我自己的结构 但对于大型输入来说构建它非常慢 是否有更好的方法来做到这一点 public static DomTree
  • ColdFusion:无效的 XML 控制字符(十六进制)

    我正在尝试使用创建一个 xml 对象
  • 日期减去 xslt 中的另一个日期

    希望有人能帮忙 我正在尝试比较 XML 文件中的 2 个日期并使用 XSLT 进行一些计算 例如 我有 2 个 XML 日期 2011 05 23 和 2011 04 29 我想在 XSLT 中进行计算 如下所示 2011 05 23 20
  • jQuery - xpath 查找?

    如果您在 xml 中有下面的 xml 那么您会使用以下命令变得昏昏欲睡 xml find animal find dog find beagle text jQuery 中是否有类似的方法来使用 xpath xml xpathfind an
  • 在 PHP 中验证约 400MB 的大型 XML 文件

    我有一个很大的 XML 文件 大约 400MB 在开始处理之前我需要确保它的格式正确 我尝试的第一件事是类似于下面的内容 这很棒 因为我可以找出 XML 是否格式不正确以及 XML 的哪些部分 不好 doc simplexml load s
  • xml 拉解析器资产 xml

    如何使用拉解析器解析资产文件夹中的本地 XML 文件 我无法让拉解析器工作 它总是抛出 io 异常 我想我无法获取文件的路径或连接到该文件 mixm 我正在尝试各种方法来从 资产 和 资源 加载本地文件 但要按要求回答您的问题 因为其他人似
  • 如何在Java中有效地读取由大量小项目组成的大型XML文件?

    我有一个很大的 XML 文件 其中包含相对固定大小的项目 即
  • Xslt 到 xsl-fo 转换

    我想将 xslt 转换为 xsl fo 但我不太确定我能做到这一点 我尝试将 XML 列表转换为 xsl fo 列表 谁能告诉我在哪里可以找到我在谷歌上搜索了很长时间没有很多这样的例子 我的XML是这样的 p TEXT p ul li It
  • 在 PHP 5 中使用 Schematron 验证 XML

    我在验证 XML 时遇到问题图解器 http en wikipedia org wiki Schematron 在我的代码中 我将 XML 和 XSL 作为 DOMDocument 对象加载 并尝试进行转换 domSche new DOMD
  • XSLT:我们可以使用abs值吗?

    我想知道在 XSLT 中我们是否可以使用 math abs 我在某处看到过这个 但它不起作用 我有类似的东西
  • 使用 XML 时引用未声明的实体异常

    我正在尝试设置 xmldoc 的 innerxml 但出现异常 Reference to undeclaredEntity XmlDocument xmldoc new XmlDocument string text Hello I am
  • 在 WSDL 中包含 XSD

    我正在编写一个 wsdl 文件来在未来 SoapUI 中部署模拟服务 但我在包含我的 xsd 文件时遇到问题 XSD File
  • XSLT;将转义文本解析为节点集并提取子元素

    我一整天都在与这个问题作斗争 几乎束手无策 我有一个 XML 文件 其中数据的某些部分存储为转义文本 但它们本身是格式良好的 XML 我想将此文本节点中的整个层次结构转换为节点集并提取其中的数据 我能想到的变量和函数的组合都不起作用 我期望
  • 使用 MemoryStream 创建 Open XML 电子表格时的 Excel 和“不可读内容”

    使用 Open XML SDK v2 0 创建 Excel 电子表格时 我们的 Excel 输出最初可以成功运行几个月 最近Excel 所有版本 开始抱怨 Excel在 zot xlsx 中发现不可读的内容 是否要恢复此工作簿的内容 我们正
  • 使用 C# 编辑 XML 文档

    我在解决如何将元素添加到 XML 文档中时遇到了一些麻烦 我想将热点信息添加到 xml 中 其中 Id 正确 因此 id 2 添加热点信息 这是我当前的 XML
  • & 在 xml 文件中算作一个还是多个字符?

    我正在使用的 XML 模式具有特定的字符串字符长度 所以我可能有一个类似的字符串 Jim Mary 在 C 中是 10 个字符 但是当它写入 xml 时 它会变成 Jim amp Mary 如果 XML 模式规定字符串最多只能有 10 个字
  • 在 XSL 中测试 xs:decimal 的正确方法是什么?

    我试图根据传入的数据显示不同的信息 如果它是整数 我想只显示数字 如果它是小数 我想使用 0 00 模式 是的 我知道 有点混乱 但这就是开发规范 gt 对于这个特定部分 我有以下 XSL 但我无法看到 xsl when 错误消息 预期的表

随机推荐