Select and transform child element attribute string value in XSL

mushin

New Member
  • How to extract \[code\]File -> Source\[/code\] value
  • and assign it as \[code\]RegistryValue -> Name\[/code\], where \[code\]RegistryValue\[/code\] is injected as a new element with the XSLT provided?
Source XML\[code\]<?xml version="1.0" encoding="utf-8"?><Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Fragment> <DirectoryRef Id="WixSlave.Binaries"> <Component Id="cmpA1D1BF677641BE2AE700859D8256B0FC" Guid="{B0BF9CBD-8A5D-43C1-B9DE-0A1B5A6BD1DE}"> <File Id="filC2827DDF7874712A62423151FBE8CE34" Source="$(var.WixSlave.TargetDir)\WixSlave.exe" /> </Component> <Component Id="cmpBC6AB890535757A915C99A10445CC74E" Guid="{8726FF82-808A-4736-AD0A-C804A34E494B}"> <File Id="fil7BD5BE5CD71AC92FF47D1D51A99FEE05" Source="$(var.WixSlave.TargetDir)\WixSlave.exe.config" /> </Component> </DirectoryRef> </Fragment> <Fragment> <ComponentGroup Id="WixSlave.Binaries"> <ComponentRef Id="cmpA1D1BF677641BE2AE700859D8256B0FC" /> <ComponentRef Id="cmpBC6AB890535757A915C99A10445CC74E" /> </ComponentGroup> </Fragment></Wix>\[/code\]XSLT Working Without Variable Name Attribute Value\[code\]<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Copy all attributes and elements to the output. --> <xsl:template match="@*|*"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="*"/> </xsl:copy> </xsl:template> <xsl:template match="wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component"> <Component> <xsl:apply-templates select="@*|*"/> <RegistryValue Name="toBeVariableKey" Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="integer" Value="http://stackoverflow.com/questions/10353986/1" KeyPath="yes"/> </Component> </xsl:template></xsl:stylesheet>\[/code\]
  • To be more specific I would like to read the \[code\]File\[/code\] element attribute \[code\]Source="$(var.WixSlave.TargetDir)\WixSlave.exe"\[/code\] and then transform it to just \[code\]WixSlaveexe\[/code\] i.e. extract from the source string only letters (a-z, A-Z), starting after last slash
  • And then assign that string to the \[code\]RegistryValue\[/code\] element \[code\]Name\[/code\] attribute, which in the sample is \[code\]Name="toBeVariableKey"\[/code\], but should become \[code\]Name="WixSlaveexe"\[/code\] for the first \[code\]Component\[/code\]
  • For the second \[code\]Component\[/code\] it should be reading from \[code\]File\[/code\] \[code\]Source="$(var.WixSlave.TargetDir)\WixSlave.exe.config"\[/code\] and adding \[code\]RegistryValue\[/code\] with \[code\]Name="WixSlaveexeconfig"\[/code\], and so on...
 
Back
Top