我需要替换
- 元素,Id 属性,值为 ZYXYZ123456
将它们替换为各自的/父级
- 目录元素,Id 属性值
输入 XML
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:wix="http://wixtoolset.org/schemas/v4/wxs">
<?include
$(sys.CURRENTDIR)DeploymentDataStatics.wxi
?>
<Fragment>
<DirectoryRef Id="TARGETFOLDER">
<Directory Id="dir3927012B444F1DB745782B917DAF8F52" Name="de">
<Component Id="cmp0B1BB8F3CC5ABCC8B2DC21EFF552B101" Guid="{61855CC1-97FD-4F9A-BE4D-58BB84E3D45F}">
<File Id="fil6E782DCD75BB9136587D1C2C3C8405DA" Source="$(var.Fundraisin.TargetDir)deSystem.Windows.Interactivity.resources.dll" />
<RemoveFolder Id="ZYXYZ123456" On="uninstall" />
<RegistryValue Root="HKCU" Key="$(var.App.Reg.Path)" Name="deSystemWindowsInteractivityresourcesdllKey" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Directory>
<Directory Id="dir030901E2EAEF85FABAA23B70A484C2DA" Name="en">
<Component Id="cmp0B23CA905283819B80BD5BCA1DD53351" Guid="{BA8BDBDA-8383-48FC-A72E-DB0BD30F8C0F}">
<File Id="filC47344F28A098B48E37BBEDF62663A84" Source="$(var.Fundraisin.TargetDir)enSystem.Windows.Interactivity.resources.dll" />
<RemoveFolder Id="ZYXYZ123456" On="uninstall" />
<RegistryValue Root="HKCU" Key="$(var.App.Reg.Path)" Name="enSystemWindowsInteractivityresourcesdllKey" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Directory>
<Component Id="cmpA1CA940DDE5CB7E5A98DA7931F3F25F2" Guid="{A6D33CD8-9235-43EC-972C-ED07B3B1E1E8}"><File Id="fil324414361723D2D64834B378C0B7C68B" Source="$(var.Fundraisin.TargetDir)Castle.Core.dll" /><RegistryValue Root="HKCU" Key="$(var.App.Reg.Path)" Name="CastleCoredllKey" Type="integer" Value="1" KeyPath="yes" /></Component>
<Component Id="cmpE41CA83817294A110F385AC18AFC4A10" Guid="{875D5B4F-E03B-4C4D-A14C-494BA2F061DA}"><File Id="filB9649B9DA6A66326E4F8C66B490ED552" Source="$(var.Fundraisin.TargetDir)Castle.Windsor.dll" /><RegistryValue Root="HKCU" Key="$(var.App.Reg.Path)" Name="CastleWindsordllKey" Type="integer" Value="1" KeyPath="yes" /></Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="Dlls">
<ComponentRef Id="cmpA1CA940DDE5CB7E5A98DA7931F3F25F2" />
<ComponentRef Id="cmpE41CA83817294A110F385AC18AFC4A10" />
<ComponentRef Id="cmp0B1BB8F3CC5ABCC8B2DC21EFF552B101" />
<ComponentRef Id="cmp0B23CA905283819B80BD5BCA1DD53351" />
</ComponentGroup>
</Fragment>
</Wix>
所需输出的一部分
...
<Directory Id="dir3927012B444F1DB745782B917DAF8F52" Name="de">
<Component Id="cmp0B1BB8F3CC5ABCC8B2DC21EFF552B101" Guid="{61855CC1-97FD-4F9A-BE4D-58BB84E3D45F}">
<File Id="fil6E782DCD75BB9136587D1C2C3C8405DA" Source="$(var.Fundraisin.TargetDir)deSystem.Windows.Interactivity.resources.dll" />
<RemoveFolder Id="dir3927012B444F1DB745782B917DAF8F52" On="uninstall" />
<RegistryValue Root="HKCU" Key="$(var.App.Reg.Path)" Name="deSystemWindowsInteractivityresourcesdllKey" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Directory>
...
XSLT 将属性值替换为另一个属性值
如何在新属性中复制属性值可能是一个开始,但我知道的 XSLT 太少而无法更进一步?
此 XSLT 样式表应该执行您想要的操作。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://wixtoolset.org/schemas/v4/wxs">
<xsl:output method="xml" indent="yes"/>
<!-- The identity transform: match nodes and attributes, copy them out and
do the same to their children i.e. output an identical copy of the input. -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Do something special when we hit a RemoveFolder element with a particular
Id attribute. The namespace for these elements has to match the one in your
input XML. -->
<xsl:template match="wix:RemoveFolder[@Id='ZYXYZ123456']">
<!-- Copy the element itself. -->
<xsl:copy>
<!-- Copy out the original attributes for this element. -->
<xsl:apply-templates select="@*"/>
<!-- Output an Id attribute. This will overwrite any existing Id attribute. -->
<xsl:attribute name="Id">
<!-- Give it the value of the Id attribute of the Directory element that
is an ancestor of this RemoveFolder element. -->
<xsl:value-of select="ancestor::wix:Directory/@Id"/>
</xsl:attribute>
<!-- Copy out the children of this element (none in your case, as it happens). -->
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>