0

I need to replace

  • the RemoveFolder element, Id attribute, values of ZYXYZ123456

replace them with their respective / parent

  • Directory element, Id attribute values

Input 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)Deployment\Data\Statics.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)\de\System.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)\en\System.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>

Part of Desired Output

            ...
            <Directory Id="dir3927012B444F1DB745782B917DAF8F52" Name="de">
                <Component Id="cmp0B1BB8F3CC5ABCC8B2DC21EFF552B101" Guid="{61855CC1-97FD-4F9A-BE4D-58BB84E3D45F}">
                    <File Id="fil6E782DCD75BB9136587D1C2C3C8405DA" Source="$(var.Fundraisin.TargetDir)\de\System.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 Substitute Attribute Value with Another Attribute Value

how to COPY Attribute value in a new attribute may be a start, but I know too little XSLT to take it further?

4

1 回答 1

1

这个 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>
于 2013-10-17T12:46:28.117 回答