如何让两个模板在同一个XSLT文件中工作?
<?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>
<?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>
<!-- Folder Template -->
<xsl:template match="wix:Wix/wix:Fragment/wix:DirectoryRef">
<DirectoryRef Id="TARGETFOLDER">
<xsl:copy-of select="*"/>
</DirectoryRef>
</xsl:template>
<!-- Registry Template -->
<xsl:template match="wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component">
<Component>
<xsl:apply-templates select="@*|*"/>
<RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Name="toBeVariableKey" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</xsl:template>
</xsl:stylesheet>
<?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>
<!-- Registry Template -->
<xsl:template match="wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component">
<Component>
<xsl:apply-templates select="@*|*"/>
<RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Name="toBeVariableKey" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:2)
你必须让模板匹配链继续。通过以下方式更改文件夹模板将帮助您:
<!-- Folder Template -->
<xsl:template match="wix:Wix/wix:Fragment/wix:DirectoryRef">
<DirectoryRef Id="TARGETFOLDER">
<xsl:apply-templates select="*"/>
</DirectoryRef>
</xsl:template>
所以基本上你必须让XSLT知道你需要继续进一步遍历节点。
更新:如果您不想复制Component
节点