创建转换(XSL)以修改加热(WiX)输出

时间:2016-08-31 21:50:36

标签: xml xslt wix

我试图改变输出热量(WiX)

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="WINSERVINSTALLDIR">
            <Component Id="Dak.IPTV2.Service.exe" 
                       Guid="DC327EF4-0456-4031-A520-46F5D8EE7930">
                <File Id="Dak.IPTV2.Service.exe" KeyPath="yes" 
                      Source="$(var.winServDir)\Dak.IPTV2.Service.exe" />
            </Component>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="WINSERV">
            <ComponentRef Id="Dak.IPTV2.Service.exe" />
        </ComponentGroup>
    </Fragment>
</Wix>

使用此XSLT文件

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>

  <!-- copy everything verbatim -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <!-- except "Component" nodes -->
  <xsl:template match="Component">
    <xsl:copy>
      <xsl:attribute name="Id">
        <xsl:value-of select="concat('WinServ_', @Id)"/>
      </xsl:attribute>
      <xsl:apply-templates select="*" />

    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

但它不起作用。我想要的是将前缀(例如WinServ_)附加到所有Component节点的Id属性的值。应用XSLT后,输出与输入相同。

有什么问题?

祝你好运

最终解决方案 感谢蒂姆和汤姆,我终于得到了我想要的东西:一个XSL转换,从热量(WiX)附加到一些输出以避免Id冲突。这是最终的XSLT文件(还有其他类似的)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
  <xsl:output method="xml" indent="yes"/>

  <!-- copy everything verbatim -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <!-- except "Component" nodes -->
  <xsl:template match="wix:Component|wix:ComponentRef|wix:File">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:attribute name="Id">
        <xsl:value-of select="concat('WebApp_', @Id)"/>
      </xsl:attribute>
      <xsl:apply-templates select="child::*" />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

1 个答案:

答案 0 :(得分:3)

您尚未考虑XSLT中的wix名称空间。在wix XML中,所有元素都在命名空间中,由根元素上的默认命名空间元素声明。

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

您的XSLT当前正在尝试匹配无命名空间中的Component元素,并且不会匹配命名空间中输入XML中的Component元素。

试试这个XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
      xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
  <xsl:output method="xml" indent="yes"/>

  <!-- copy everything verbatim -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <!-- except "Component" nodes -->
  <xsl:template match="wix:Component">
    <xsl:copy>
      <xsl:attribute name="Id">
        <xsl:value-of select="concat('WinServ_', @Id)"/>
      </xsl:attribute>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

注意wix前缀的使用在这里是任意的。它可以是你选择的任何东西,只要命名空间uri匹配。