【发布时间】:2015-10-12 09:55:56
【问题描述】:
我正在通过 xslt 编辑 directory.wxs 中所有 .config 文件的组件。
1) 到达子元素(文件)后,我无法转到父元素(组件)
2) 它覆盖所有属性,而不是附加到原始属性。
我的 xslt 文件
<?xml version="1.0" encoding="utf-8"?>
<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:my="my:my">
<xsl:output method="xml" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match='/wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Directory/wix:Directory/wix:Component/wix:File[@Source="SourceDir\Debug\settings.xml"]'>
<xsl:copy>
<xsl:apply-templates select=".." mode="backout"/>
<xsl:attribute name="Permanent">
<xsl:text>yes</xsl:text>
</xsl:attribute>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
输入.wxs
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Directory Id="dirEF46C7404B50F3071431995F0F04741E" Name="bin">
<Component Id="cmp1B2A20D6C7B8EEB0F3E75C2D993AAC13" Guid="1346D980-EE76-4E6D-BA63-F1F0BB5A860D">
<File Id="fil46D415998FC8ECAB7106CB3185135601" KeyPath="yes" Source="SourceDir\Debug\settings.xml" />
</Component>
</Directory>
</Directory>
</DirectoryRef>
</Fragment>
输出.xml
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Directory Id="dirEF46C7404B50F3071431995F0F04741E" Name="bin">
<Component Id="cmp1B2A20D6C7B8EEB0F3E75C2D993AAC13" Guid="1346D980-EE76-4E6D-BA63-F1F0BB5A860D">
<File Permanent="yes" />
</Component>
</Directory>
</Directory>
</DirectoryRef>
</Fragment>
需要的输出.xml
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Directory Id="dirEF46C7404B50F3071431995F0F04741E" Name="bin">
<Component Id="cmp1B2A20D6C7B8EEB0F3E75C2D993AAC13" Guid="1346D980-EE76-4E6D-BA63-F1F0BB5A860D" Permanent="yes" >
<File Id="fil46D415998FC8ECAB7106CB3185135601" KeyPath="yes" Source="SourceDir\Debug\settings.xml" />
</Component>
</Directory>
</Directory>
</DirectoryRef>
</Fragment>
【问题讨论】:
-
请更新您的 XML 以使其格式正确。遍历到父元素的目的是什么?
-
permanent = yes 应该定义在组件标签而不是文件标签中
-
@abhinavpandey 你的编辑是什么意思? OP 希望将
permanent属性添加到File元素,而不是Component。你怎么比他/她更了解这个? -
它是wix,永久属性是文件标签的一部分:)