如何在xsl转换期间向组件添加条件? [英] How to add condition to component during xsl transformation?

查看:96
本文介绍了如何在xsl转换期间向组件添加条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在xdir转换期间在wix中添加组件条件,该转换在收获dir期间应用.我尝试了此模板,但无法正常工作.

I am trying to add component condition in wix during xsl transformation that is applied during harvesting a dir. I tried this template but it is not working.

<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:netfx="http://schemas.microsoft.com/wix/NetFxExtension"
                xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <xsl:output method="xml" indent="yes" />

  <xsl:strip-space elements="*" />


  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="wix:Component">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
         <Condition Level="1"><![CDATA[MYPROP="1"]]></Condition>
    </xsl:copy>
  </xsl:template>

虽然heat.exe的输入将是目录位置,并且xml的生成将通过Heat和转换完成,但我认为充当输入的中间xml将是

Although the input to the heat.exe will be directory location and xml generation will be done by heat along with transformation I think the intermediate xml that serves as input will be

输入

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="MyDir">
            <Component Id="CefSharp.BrowserSubprocess.Core.dll_x86" Guid="06CF68DB-C4D3-45D3-8619-982C7963ADC6">
                <File Id="CefSharp.BrowserSubprocess.Core.dll_x86" KeyPath="yes" Source="$(var.CefSharpDirx86)\CefSharp.BrowserSubprocess.Core.dll" />

            </Component>

        </DirectoryRef>
    </Fragment>
</Wix>

输出

 <?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

         <Fragment>
                <DirectoryRef Id="MyDir">
                    <Component Id="CefSharp.BrowserSubprocess.Core.dll_x86" Guid="06CF68DB-C4D3-45D3-8619-982C7963ADC6">
                        <File Id="CefSharp.BrowserSubprocess.Core.dll_x86" KeyPath="yes" Source="$(var.CefSharpDirx86)\CefSharp.BrowserSubprocess.Core.dll" />
                      <Condition Level="1"><![CDATA[MYPROP="1"]]></Condition>
                    </Component>

                </DirectoryRef>
            </Fragment>
    </Wix>

我是XSLT世界的新手.请提出建议.

I am new to the XSLT world. Please suggest.

推荐答案

-为澄清起见进行编辑-

-- edited in response to clarification --

不确定不工作"是什么意思.当然,您必须将新元素放置在与其父元素相同的名称空间中,以便获得预期的结果:

Not sure what you mean by "not working". Certainly, you must place the new element in the same namespace as its parent in order to get the intended result:

XSLT 1.0

<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" indent="yes" cdata-section-elements="wix:Condition"/>
<xsl:strip-space elements="*" />

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

<xsl:template match="wix:Component">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
        <xsl:element name="Condition" namespace="http://schemas.microsoft.com/wix/2006/wi">
            <xsl:attribute name="level">1</xsl:attribute>
            <xsl:text>MYPROP="1"</xsl:text>
        </xsl:element>  
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

查看它的工作原理: http://xsltransform.net/bFN1yai

这篇关于如何在xsl转换期间向组件添加条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆