2016-04-14 35 views
0

我正在嘗試在收穫目錄期間應用的xsl轉換期間在wix中添加組件條件。我試過這個模板,但它不工作。如何在xsl轉換過程中向組件添加條件?

<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生成將由熱與改造一起做我認爲,作爲輸入將中間XML

輸入

<?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世界。請建議。

+1

請告訴我們的輸入示例和預期輸出 - 請參閱:[mcve]。 –

+0

@ michael.hor257k:添加了輸入和期望輸出的示例 – Sameer

+0

您的輸入不在'wix:'命名空間中,因此您的模板不匹配任何內容。 –

回答

1

- 響應編輯,以澄清 -

不知道你的 「不工作」 的意思。當然,你必須將新的元素在同一個名稱空間作爲其母公司,以獲得預期的結果:

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

+0

我不知道命名空間的規則,所以一些如何輸出亂七八糟的所有不同的名稱空間.. Anyway ..感謝解決方案..轉換工作,但價值沒有被包裹到CDATA在我的情況。 – Sameer

+0

「*值沒有被包裹到CDATA *」它在我的[demo]中(http://xsltransform.net/bFN1yai)。你是否完全複製它 - 具體是'cdata-section-elements'屬性? –

+0

是的,我做到了..雖然這不是一個問題,我有一個解決方案.. <![CDATA [我現在已經添加了這個 – Sameer