6

我正在收集一个带有热量的文件,我真的很想给它一个像样的 ID,而不是通常的“filXXXXXXXX”,主要是因为我需要在安装程序的其他部分引用它。我知道 Id 在不同的机器上和不同的文件内容上总是相同的,所以我可以放心地使用它,比如在 CI 服务器上构建时它不会改变。

当然,让这个值更加人性化会更好。似乎 Heat 没有生成文件 ID 的命令行选项(编辑:显然有一个 -suid 选项将停止生成数字 ID 并仅使用文件名作为 ID,无论如何这在很多情况下都是不可行的) ,所以我正在经历编写 XSLT 的痛苦,但无法实现我想要的,有人可以帮忙吗?

这是片段文件:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="DBScripts" />
    </Fragment>
    <Fragment>
        <ComponentGroup Id="CSInstallerConfig">
            <Component Id="cmpD6BAFC85C2660BE8744033953284AB03" Directory="DBScripts" Guid="{A39BABF5-2BAC-46EE-AE01-3B47D6C1C321}">
                <File Id="filB31AC19B3A3E65393FF9059147CDAF60" KeyPath="yes" Source="$(var.CONFIG_PATH)\CSInstaller.config" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>

这是 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">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@*|*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="File">
        <xsl:attribute name="Id">
            <xsl:value-of select="123"/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

现在,我是 XSL 的真正菜鸟,所以也许上面的文件完全是胡说八道,但无论如何,发生的事情是“文件”元素被立即复制而没有更改 ID。

任何的想法?

4

1 回答 1

6

您的基本问题是名称空间或您的 XML 根元素 wi。您没有解决这个问题,因此 XSLT 实际上根本找不到您的 File 元素。

接下来,您必须对模板进行一些调整以正确复制 File 的其他属性:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:wi="http://schemas.microsoft.com/wix/2006/wi">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@*|*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="wi:File">
        <xsl:copy>
            <xsl:attribute name="Id">
                <xsl:value-of select="123"/>
            </xsl:attribute>
            <xsl:apply-templates select="@*[not(name()='Id')]" />
            <xsl:apply-templates select="*" />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
于 2012-07-20T11:24:41.910 回答