0
  • 如何提取File -> Source价值
  • 并将其分配为RegistryValue -> NameRegistryValue作为提供 XSLT 的新元素注入到哪里?

源 XML

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="WixSlave.Binaries">
            <Component Id="cmpA1D1BF677641BE2AE700859D8256B0FC" Guid="{B0BF9CBD-8A5D-43C1-B9DE-0A1B5A6BD1DE}">
                <File Id="filC2827DDF7874712A62423151FBE8CE34" Source="$(var.WixSlave.TargetDir)\WixSlave.exe" />
            </Component>
            <Component Id="cmpBC6AB890535757A915C99A10445CC74E" Guid="{8726FF82-808A-4736-AD0A-C804A34E494B}">
                <File Id="fil7BD5BE5CD71AC92FF47D1D51A99FEE05" Source="$(var.WixSlave.TargetDir)\WixSlave.exe.config" />
            </Component>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="WixSlave.Binaries">
            <ComponentRef Id="cmpA1D1BF677641BE2AE700859D8256B0FC" />
            <ComponentRef Id="cmpBC6AB890535757A915C99A10445CC74E" />
        </ComponentGroup>
    </Fragment>
</Wix>

XSLT 在没有变量名称属性值的情况下工作

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- Copy all attributes and elements to the output. -->
    <xsl:template match="@*|*">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates select="*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component">
        <Component>
            <xsl:apply-templates select="@*|*"/>
            <RegistryValue Name="toBeVariableKey" Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="integer" Value="1" KeyPath="yes"/>
        </Component>
    </xsl:template>
</xsl:stylesheet>
  • 更具体地说,我想阅读File元素属性Source="$(var.WixSlave.TargetDir)\WixSlave.exe",然后将其转换为仅从WixSlaveexe 源字符串中提取字母(az,AZ),从最后一个斜杠之后开始
  • 然后将该字符串分配给RegistryValue元素Name属性,在示例中是Name="toBeVariableKey",但应该成为Name="WixSlaveexe"第一个Component

  • 对于第二个Component,它应该读取File Source="$(var.WixSlave.TargetDir)\WixSlave.exe.config"并添加RegistryValuewith Name="WixSlaveexeconfig",依此类推......

4

1 回答 1

2

您可以使用属性值模板来设置名称

<RegistryValue Name="{substring-after(wix:File/@Source, '\')}" />

这应该在第一个斜杠之后提取子字符串,并将结果分配给属性name

要从文本中删除任何点,您可以使用翻译功能,如下所示

<RegistryValue Name="{translate(substring-after(wix:File/@Source, '\'), '.', '')}" />
于 2012-04-27T16:18:20.813 回答