modify WXS file generated by heat through Xslt
我正在通过 xslt 编辑 directory.wxs 中所有 .config 文件的组件。
1) 到达子元素(文件)
后我无法转到父元素(组件)
2) 它覆盖所有属性而不是附加到原始属性。
我的 xslt 文件
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?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:template match=‘/wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Directory/wix:Directory/wix:Component/wix:File[@Source=”SourceDir\\Debug\\settings.xml”]’> </xsl:stylesheet> |
输入.wxs
1
2 3 4 5 6 7 8 9 10 11 12 |
<?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
1
2 3 4 5 6 7 8 9 10 11 12 |
<?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
1
2 3 4 5 6 7 8 9 10 11 12 |
<?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,使其格式正确。遍历到父元素的目的是什么?
- 永久=yes 应该在组件标签而不是文件标签中定义
- @abhinavpandey 你的编辑是什么意思? OP 希望将 permanent 属性添加到 File 元素,而不是 Component。你怎么比他/她更了解这件事?
- 它是 wix,永久属性是文件标签的一部分 :)
试试这个方法:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<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” version=“1.0” encoding=“UTF-8” indent=“yes”/> <xsl:strip-space elements=“*”/> <!– identity transform —> <xsl:template match=“wix:File[@Source=’SourceDir\\Debug\\settings.xml’]”> </xsl:stylesheet> |
I am unable to go to parent element(component) after reaching child
element(file)
我认为没有必要这样做。如果要修改父级,只需添加一个匹配 Component 的模板并让它在到达子级之前执行即可。
另请注意,您的样式表尝试使用 mode=”backout” 将模板应用于 File 的父级 – 但在这种模式下它不包含模板。
无论如何,您的预期输出显示父 Component 没有变化,所以这都是理论上的。
编辑:
针对您编辑的问题和以下评论中的澄清:
I want to add attribute in the component for which corresponding child
(File elemeny) satisfy the condition that
source=”SourceDir\\Debug\\settings.xml”
将第二个模板更改为:
1
2 3 4 5 6 |
<xsl:template match=“wix:Component[wix:File/@Source=’SourceDir\\Debug\\settings.xml’]”>
<xsl:copy> <xsl:attribute name=“Permanent”>yes</xsl:attribute> <xsl:apply-templates select=“@*|node()”/> </xsl:copy> </xsl:template> |
- 但是没有关于我的组件的任何先前信息,因为我的 directory.wxs 文件是由 WIX heat 命令生成的。我能做的就是通过它的子元素 File 来唯一标识该组件
- @Keshav恐怕我不明白你想说什么。您要修改 File 还是 Component?如果是 Component,您的输入中是否还有其他 Component 元素?
- 我想在组件中添加属性,其对应的子项(文件元素)满足 source=”SourceDir\\\\Debug\\\\settings.xml” 的条件
- @ michael.hor257k …Thankx 这是正确的,但问题是,它也在重新处理文件元素,这是不希望的。我需要原样的文件元素。
来源:https://www.codenong.com/31564578/