I am generating a .wxs
file using Wix Toolset v4, but it's producing an invalid output. It's trivial to fix manually, but I'd like to fix it automatically if possible.
It produces XML of this form:
<!-- Starting XML -->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<DirectoryRef />
</Fragment>
<Fragment>
<ComponentGroup>
<Component>
<File />
<RegistryValue />
<TypeLib>
<!-- Child Interface nodes. -->
</TypeLib>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
And I would like to transform it, using an XSLT stylesheet applying during the call to heat.exe
into this:
<!-- Desired XML -->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<DirectoryRef />
</Fragment>
<Fragment>
<ComponentGroup>
<Component>
<File>
<TypeLib Language="0">
<!-- Child Interface nodes. -->
</TypeLib>
</File>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Which accomplishes three tasks:
- Removes the
RegistryValue
node. - Adds the
Language="0"
attribute to theTypeLib
node. - Moves the
TypeLib
node, a sibling of theFile
node, into theFile
node as a child.
I have a stylesheet that accomplishes 1 and 2, but I have no idea how to do 2 and 3 at the same time:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:wix="http://wixtoolset.org/schemas/v4/wxs">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- Remove the RegistryValue attribute. -->
<xsl:template match="wix:RegistryValue" />
<!-- Add the missing Language="0" attribute to the TypeLib component. -->
<xsl:template match="wix:TypeLib" name="add-language">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="Language">0</xsl:attribute>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
<!-- Select the file node and make the typelib node a child. -->
<xsl:template match="wix:File">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:call-template name="add-language" />
<!--<xsl:copy-of select="following-sibling::wix:TypeLib[1]" />-->
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="wix:TypeLib[preceding-sibling::*[1][self::wix:File]]" />
</xsl:stylesheet>