2017-07-19 1 views
0

Je travaille sur wix, et j'ai besoin d'installer un service Windows. Dans le cadre de cela, je dois définir KeyPath="yes" uniquement sur le service exécutable. J'utilise HarvestDirectory tâche qui produit une sortie comme ceci:XSLT remplacer les attributs sur tous les nœuds sauf pour un

<?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> 

Ce que je veux faire est d'écrire un XSLT qui va changer KeyPath à « non » pour tous les fichiers, sauf si Source = $(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.exe

Par ex exemple de sortie serait:

<?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> 

J'ai la XSLT suivante qui remplace « oui » par « non » sur tous les attributs 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> 

J'ai essayé manipuler le match dans le deuxième modèle à l'aide parent , ancestor et simple noeud avec attributs File[@KeyPath='yes'] sélecteurs en vain.

+0

'File [@ KeyPath = 'yes']' ne sélectionne rien quand 'File' est dans un ** namespace ** - voir: https://stackoverflow.com/questions/34758492/xslt-transform-doesnt -work-until-i-remove-root-node/34762628 # 34762628 –

+0

@ michael.hor257k bien sûr, mais comment puis-je remplacer tous sauf un? – zaitsman

Répondre

2

Ce que je veux faire est d'écrire un XSLT qui va changer KeyPath à « non » pour tous les fichiers, sauf si Source = $(var.My.Awesome.Product.TargetDir)\My.Awesome.Product.exe

Cette partie serait écrit:

<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> 

Notez que cela fait pas faites ce que vous avez dit au début de votre question:

Je dois définir KeyPath="yes" uniquement sur l'exécutable du service.

Je ne suis pas sûr de ce que cela signifie et je suis encore plus confus par le fait que votre entrée ne correspond pas à votre sortie.

+0

Merci beaucoup, cela a fonctionné! – zaitsman