xsl转换时如何给组件添加条件?
How to add condition to component during xsl transformation?
我正在尝试在获取目录期间应用的 xsl 转换期间在 wix 中添加组件条件。我试过这个模板,但它不起作用。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<Condition Level="1"><![CDATA[MYPROP="1"]]></Condition>
</xsl:copy>
</xsl:template>
尽管 heat.exe 的输入将是目录位置,并且 xml 生成将通过加热和转换完成,但我认为用作输入的中间 xml 将是
输入
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="MyDir">
<Component Id="CefSharp.BrowserSubprocess.Core.dll_x86" Guid="06CF68DB-C4D3-45D3-8619-982C7963ADC6">
<File Id="CefSharp.BrowserSubprocess.Core.dll_x86" KeyPath="yes" Source="$(var.CefSharpDirx86)\CefSharp.BrowserSubprocess.Core.dll" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
输出
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="MyDir">
<Component Id="CefSharp.BrowserSubprocess.Core.dll_x86" Guid="06CF68DB-C4D3-45D3-8619-982C7963ADC6">
<File Id="CefSharp.BrowserSubprocess.Core.dll_x86" KeyPath="yes" Source="$(var.CefSharpDirx86)\CefSharp.BrowserSubprocess.Core.dll" />
<Condition Level="1"><![CDATA[MYPROP="1"]]></Condition>
</Component>
</DirectoryRef>
</Fragment>
</Wix>
我是 XSLT 世界的新手。请提出建议。
-- 根据澄清进行编辑--
不确定 "not working" 是什么意思。当然,您必须将新元素放在与其父元素相同的命名空间中才能获得预期结果:
XSLT 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 method="xml" indent="yes" cdata-section-elements="wix:Condition"/>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="Condition" namespace="http://schemas.microsoft.com/wix/2006/wi">
<xsl:attribute name="level">1</xsl:attribute>
<xsl:text>MYPROP="1"</xsl:text>
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我正在尝试在获取目录期间应用的 xsl 转换期间在 wix 中添加组件条件。我试过这个模板,但它不起作用。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<Condition Level="1"><![CDATA[MYPROP="1"]]></Condition>
</xsl:copy>
</xsl:template>
尽管 heat.exe 的输入将是目录位置,并且 xml 生成将通过加热和转换完成,但我认为用作输入的中间 xml 将是
输入
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="MyDir">
<Component Id="CefSharp.BrowserSubprocess.Core.dll_x86" Guid="06CF68DB-C4D3-45D3-8619-982C7963ADC6">
<File Id="CefSharp.BrowserSubprocess.Core.dll_x86" KeyPath="yes" Source="$(var.CefSharpDirx86)\CefSharp.BrowserSubprocess.Core.dll" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
输出
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="MyDir">
<Component Id="CefSharp.BrowserSubprocess.Core.dll_x86" Guid="06CF68DB-C4D3-45D3-8619-982C7963ADC6">
<File Id="CefSharp.BrowserSubprocess.Core.dll_x86" KeyPath="yes" Source="$(var.CefSharpDirx86)\CefSharp.BrowserSubprocess.Core.dll" />
<Condition Level="1"><![CDATA[MYPROP="1"]]></Condition>
</Component>
</DirectoryRef>
</Fragment>
</Wix>
我是 XSLT 世界的新手。请提出建议。
-- 根据澄清进行编辑--
不确定 "not working" 是什么意思。当然,您必须将新元素放在与其父元素相同的命名空间中才能获得预期结果:
XSLT 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 method="xml" indent="yes" cdata-section-elements="wix:Condition"/>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:Component">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="Condition" namespace="http://schemas.microsoft.com/wix/2006/wi">
<xsl:attribute name="level">1</xsl:attribute>
<xsl:text>MYPROP="1"</xsl:text>
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>