XSL模板复制和添加元素


<ComponentGroup Id="SimulatorComponentGroup">
   <Component Id="cmpCAB8CD4B3E3F5DE9BD27E4BE2C6D4ED5" Directory="Simulator" Guid="*">
       <File Id="fil763F3807501181AEBB3384E197DA1B60" KeyPath="yes" Source="$(var.SimulatorSourcePath)aeStatGridWeights.txt" />
   </Component>
   <Component Id="cmp9FA0A11B61A218ED2C433E82749C7264" Directory="Simulator" Guid="*">
       <File Id="fil52CCB4416F79DAB20B21723321A693FD" KeyPath="yes" Source="$(var.SimulatorSourcePath)afStatGridWeights.txt" />
   </Component>
   <Component Id="cmp8EFEB6EE1903B8CF488FED2D3754A8CF" Directory="Simulator" Guid="*">
       <File Id="fil035410628EFD654283E0E6A32D1985C4" KeyPath="yes" Source="$(var.SimulatorSourcePath)anr_black_ag1_dl65_p80_sc1.ate_config" />
   </Component>

我想创建一个输出如下内容的模板:

<ComponentGroup Id="SimulatorComponentGroup">
    <Component Id="cmpCAB8CD4B3E3F5DE9BD27E4BE2C6D4ED5" Directory="Simulator" Guid="*">
        <File Id="fil763F3807501181AEBB3384E197DA1B60" KeyPath="yes" Source="$(var.SimulatorSourcePath)aeStatGridWeights.txt" />
        <RemoveFolder Id="cmpCAB8CD4B3E3F5DE9BD27E4BE2C6D4ED5" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software[Manufacturer][ProductName]" Type="string" Value="" KeyPath="yes" />
    </Component>
    <Component Id="cmp9FA0A11B61A218ED2C433E82749C7264" Directory="Simulator" Guid="*">
        <RemoveFolder Id="cmp9FA0A11B61A218ED2C433E82749C7264" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software[Manufacturer][ProductName]" Type="string" Value="" KeyPath="yes" />
        <File Id="fil52CCB4416F79DAB20B21723321A693FD" KeyPath="yes" Source="$(var.SimulatorSourcePath)afStatGridWeights.txt" />
    </Component>
    <Component Id="cmp8EFEB6EE1903B8CF488FED2D3754A8CF" Directory="Simulator" Guid="*">
        <RemoveFolder Id="cmp8EFEB6EE1903B8CF488FED2D3754A8CF" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software[Manufacturer][ProductName]" Type="string" Value="" KeyPath="yes" />
        <File Id="fil035410628EFD654283E0E6A32D1985C4" KeyPath="yes" Source="$(var.SimulatorSourcePath)anr_black_ag1_dl65_p80_sc1.ate_config" />
    </Component>

这是我的*。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="*"/>

  <xsl:template match="@*|*">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:apply-templates select="*" />
    </xsl:copy>
  </xsl:template>
  <xsl:output method="xml" indent="yes" />

 <xsl:template match="wix:Component[@Directory='Simulator']">
    <xsl:copy>
      <xsl:attribute name="Id">
        <xsl:value-of select="./Id"/>
      </xsl:attribute>
      <xsl:apply-templates/>
      <RemoveFolder Id=""></RemoveFolder>
      <RegistryValue Root="HKCU" Key="Software[Manufacturer][ProductName]" Type="string" Value="" KeyPath="yes" />      
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

当我使用复制时,我正在从组件属性中删除Id目录,以及如何从Compnent Id="复制Id到attribute

我认为你的问题不太清楚,但也许这可以让你走上正确的道路:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="Component">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
        <RemoveFolder Id="{@Id}" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software[Manufacturer][ProductName]" Type="string" Value="" KeyPath="yes" />
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>

在匹配"Component"的模板中注意:

  1. 应用模板复制现有的属性和子节点;
  2. 使用属性值模板从Component/@Id获取值到RemoveFolder/@Id。

编辑:

为了将<File>(或任何现有的子节点)放在 <RemoveFolder><RegistryValue>之后,将第二个模板更改为:
<xsl:template match="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>

相关内容

  • 没有找到相关文章

最新更新