问题
I am trying to add component condition in wix during xsl transformation that is applied during harvesting a dir. I tried this template but it is not working.
<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>
Although the input to the heat.exe will be directory location and xml generation will be done by heat along with transformation I think the intermediate xml that serves as input will be
Input
<?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>
Output
<?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>
I am new to the XSLT world. Please suggest.
回答1:
-- edited in response to clarification --
Not sure what you mean by "not working". Certainly, you must place the new element in the same namespace as its parent in order to get the intended result:
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>
See it working: http://xsltransform.net/bFN1yai
来源:https://stackoverflow.com/questions/36628509/how-to-add-condition-to-component-during-xsl-transformation