2017-07-19 78 views
0

我正在使用wix,并且需要安装Windows服务。 作为其中的一部分,我只需要在服务可执行文件上设置KeyPath="yes"。 我使用HarvestDirectory任务,其输出像这样:XSLT替换除一个节点以外的所有节点上的属性

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
     <DirectoryRef Id="INSTALLFOLDER"> 
      <Component Id="cmp4BB0346D363B37CAFD72ED8BBAFE3DC3" Guid="*"> 
       <File Id="fil1F519C40510B9CE08968AFE1141C5124" KeyPath="yes" Source="$(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.dll" /> 
      </Component> 
     <!-- Many more here --> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <ComponentGroup Id="ProductFiles"> 
      <ComponentRef Id="cmp4BB0346D363B37CAFD72ED8BBAFE3DC3" /> 
      <!-- Many more here --> 
     </ComponentGroup> 
    </Fragment> 
</Wix> 

我想要做的是写一个XSLT会改变的keyPath为“no”的所有文件,除非源= $(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.exe

例如样本输出将是:

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
     <DirectoryRef Id="INSTALLFOLDER"> 
      <Component Id="cmp4BB0346D363B37CAFD72ED8BBAFE3DC3" Guid="*"> 
      <!-- note the 'no' in the KeyPath here --> 
       <File Id="fil1F519C40510B9CE08968AFE1141C5124" KeyPath="no" Source="$(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.dll" /> 
      </Component> 
      <Component Id="cmp5BB0346D363B37CAFD72ED8BBAFE3DC3" Guid="*"> 
       <File Id="fil2F519C40510B9CE08968AFE1141C5124" KeyPath="yes" Source="$(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.exe" /> 
      </Component> 
     <!-- Many more here --> 
     </DirectoryRef> 
    </Fragment> 
    <Fragment> 
     <ComponentGroup Id="ProductFiles"> 
      <ComponentRef Id="cmp4BB0346D363B37CAFD72ED8BBAFE3DC3" /> 
      <ComponentRef Id="cmp5BB0346D363B37CAFD72ED8BBAFE3DC3" /> 
      <!-- Many more here --> 
     </ComponentGroup> 
    </Fragment> 
</Wix> 

我有以下XSLT替换“是”与“否”上的所有的keyPath属性:

<?xml version="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:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="@KeyPath"> 
     <xsl:attribute name="KeyPath"> 
      <xsl:value-of select="'no'"/> 
     </xsl:attribute> 
    </xsl:template> 
</xsl:stylesheet> 

我试着用parent操纵比赛的第二个模板,ancestor和具有属性的简单节点File[@KeyPath='yes']选择器无济于事。

+0

'File [@KeyPath ='yes']'当'File'位于**名称空间中时不会选择任何内容** - 请参阅:https://stackoverflow.com/questions/34758492/xslt-transform-doesnt -work-until-i-remove-root-node/34762628#34762628 –

+0

@ michael.hor257k当然,但是我怎样才能取代除了一个之外的所有? – zaitsman

回答

2

我想要做的是写一个XSLT会改变的keyPath为“no”的所有文件,除非源= $(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.exe

这部分将被写成:

<xsl:template match="wix:File[not(@Source='$(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.exe')]/@KeyPath"> 
    <xsl:attribute name="KeyPath"> 
     <xsl:value-of select="'no'"/> 
    </xsl:attribute> 
</xsl:template> 

请注意,这是的不是做你在你的问题开始时说的:

我只需要在服务可执行文件上设置KeyPath="yes"

我不确定这是什么意思,我更加困惑的是,您的输入与您的输出不匹配。

+0

非常感谢,这工作! – zaitsman