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: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
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> |
试试这个方法:
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="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="wix:File[@Source='SourceDir\\Debug\\settings.xml']"> <xsl:copy> <xsl:attribute name="Permanent">yes</xsl:attribute> <xsl:copy-of select="@*"/> </xsl:copy> </xsl:template> </xsl:stylesheet> |
I am unable to go to parent element(component) after reaching child
element(file)
我认为没有必要这样做。如果要修改父级,只需添加一个匹配
另请注意,您的样式表尝试使用
无论如何,您的预期输出显示父
编辑:
针对您编辑的问题和以下评论中的澄清:
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> |