Reputation: 2027
I am editing component of all .config files in directory.wxs by xslt.
1) I am unable to go to parent element(component) after reaching child element(file)
2) It is overriding all the attributes rather than appending to original attributes.
my xslt file
<?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>
input.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>
output.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>
requiredoutput.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>
Upvotes: 2
Views: 1272
Reputation: 117073
Try it this way:
<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 see no need to do so. If you want to modify the parent, you can do it simply by adding a template matching Component
and let it execute before reaching the child.
Note also that your stylesheet tries to apply template to the parent of File
using mode="backout"
- but it contains no templates in such mode.
In any case, your expected output shows no change to the parent Component
, so this is all theoretical.
In response to your edited question and the clarification in the comment below:
I want to add attribute in the component for which corresponding child (File elemeny) satisfy the condition that source="SourceDir\Debug\settings.xml"
Change the second template to:
<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>
Upvotes: 3