wix heat使用xsl文件删除命名空间

时间:2014-07-06 20:56:10

标签: xml xslt wix wix3.6 wix3.7

这是我的预构建脚本:

"%WIX%\bin\heat.exe" dir "$(SolutionDir)Export\Release\SkyCam\Config" -t   "$(SolutionDir)IQStudioInstaller\SimulatorIgnore.xsl" -dr Simulator -srd -cg SimulatorComponentGroup -var var.SimulatorSourcePath -ag -sreg -out "$(SolutionDir)IQStudioInstaller\IQStudioSimulatorDir.wxs"

这是我的* .xsl文件:

<?xml version="1.0" ?>
<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 omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
  <xsl:strip-space  elements="*"/>
  <!-- identity transform -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="wix:Component">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <RemoveFolder Id="{@Id}" On="uninstall" />
      <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

我遇到的问题是添加了 xlmns 属性,该属性已添加到我的和:

的xmlns =&#34;&#34;的xmlns:威克斯=&#34; HTTP://schemas.microsoft.com/wix/2006/wi"

为什么要添加它以及如何删除它?


<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="Simulator" />
    </Fragment>
    <Fragment>
        <ComponentGroup Id="SimulatorComponentGroup">
            <Component Id="cmpCAB8CD4B3E3F5DE9BD27E4BE2C6D4ED5" Directory="Simulator" Guid="*">
                <RemoveFolder Id="cmpCAB8CD4B3E3F5DE9BD27E4BE2C6D4ED5" On="uninstall" **xmlns="" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"** />
                <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" xmlns="" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" />
                <File Id="fil763F3807501181AEBB3384E197DA1B60" KeyPath="yes" Source="$(var.SimulatorSourcePath)\aeStatGridWeights.txt" />
            </Component>
            <Component Id="cmp9FA0A11B61A218ED2C433E82749C7264" Directory="Simulator" Guid="*">
                <RemoveFolder Id="cmp9FA0A11B61A218ED2C433E82749C7264" On="uninstall" **xmlns="" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"** />
                <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" xmlns="" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" />
                <File Id="fil52CCB4416F79DAB20B21723321A693FD" KeyPath="yes" Source="$(var.SimulatorSourcePath)\afStatGridWeights.txt" />
            </Component>

更新

我像Tim建议编辑我的* .xsl文件,它解决了其中一个问题

<?xml version="1.0" ?>
<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">

  <xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
  <xsl:strip-space  elements="*"/>
  <!-- identity transform -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="wix:Component">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <RemoveFolder Id="{@Id}" On="uninstall" />
      <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

现在的输出是:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="Simulator" />
    </Fragment>
    <Fragment>
        <ComponentGroup Id="SimulatorComponentGroup">
            <Component Id="cmpCAB8CD4B3E3F5DE9BD27E4BE2C6D4ED5" Directory="Simulator" Guid="*">
                <wix:RemoveFolder Id="cmpCAB8CD4B3E3F5DE9BD27E4BE2C6D4ED5" On="uninstall" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" />
                <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" />
                <File Id="fil763F3807501181AEBB3384E197DA1B60" KeyPath="yes" Source="$(var.SimulatorSourcePath)\aeStatGridWeights.txt" />
            </Component>
            <Component Id="cmp9FA0A11B61A218ED2C433E82749C7264" Directory="Simulator" Guid="*">
                <wix:RemoveFolder Id="cmp9FA0A11B61A218ED2C433E82749C7264" On="uninstall" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" />
                <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" />
                <File Id="fil52CCB4416F79DAB20B21723321A693FD" KeyPath="yes" Source="$(var.SimulatorSourcePath)\afStatGridWeights.txt" />
            </Component>

所以xmlns=""已经消失了! 但它没有解决xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"

1 个答案:

答案 0 :(得分:1)

问题在于这些行

  <RemoveFolder Id="{@Id}" On="uninstall" />
  <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />

您正在输出NO命名空间中的元素,但对于您的Wix文件,它们需要进入“http://schemas.microsoft.com/wix/2006/wi”命名空间。

您可以通过为元素

指定相关的名称空间前缀来轻松解决此问题
  <wix:RemoveFolder Id="{@Id}" On="uninstall" />
  <wix:RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />

或者,您也可以将wix名称空间作为默认名称空间添加到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">

这样,没有名称空间前缀的元素实际上将成为默认名称空间的一部分。

相关问题