ExcludeComponents.xslt 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
  5. xmlns="http://schemas.microsoft.com/wix/2006/wi"
  6. version="1.0"
  7. exclude-result-prefixes="xsl wix" >
  8. <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
  9. <xsl:strip-space elements="*"/>
  10. <!--
  11. Find all <Component> elements with <File> elements with Source="" attributes ending in ".exe" and tag it with the "ExeToRemove" key.
  12. <Component Id="cmpSYYKP6B1M7WSD5KLEQ7PZW4YLOPYG61L" Directory="INSTALLDIR" Guid="*">
  13. <File Id="filKUS7ZRMJ0AOKDU6ATYY6IRUSR2ECPDFO" KeyPath="yes" Source="!(wix.StagingAreaPath)\ProofOfPEqualsNP.exe" />
  14. </Component>
  15. Because WiX's Heat.exe only supports XSLT 1.0 and not XSLT 2.0 we cannot use `ends-with( haystack, needle )` (e.g. `ends-with( wix:File/@Source, '.exe' )`...
  16. ...but we can use this longer `substring` expression instead (see https://github.com/wixtoolset/issues/issues/5609 )
  17. -->
  18. <xsl:key
  19. name="UltiMaker_Cura_exe_ToRemove"
  20. match="wix:Component[ substring( wix:File/@Source, string-length( wix:File/@Source ) - 17 ) = 'UltiMaker-Cura.exe' ]"
  21. use="@Id"
  22. />
  23. <xsl:key
  24. name="CuraEngine_exe_ToRemove"
  25. match="wix:Component[ substring( wix:File/@Source, string-length( wix:File/@Source ) - 17 ) = 'CuraEngine.exe' ]"
  26. use="@Id"
  27. />
  28. <!-- By default, copy all elements and nodes into the output... -->
  29. <xsl:template match="@*|node()">
  30. <xsl:copy>
  31. <xsl:apply-templates select="@*|node()"/>
  32. </xsl:copy>
  33. </xsl:template>
  34. <!-- ...but if the element has the "UltiMaker_Cura_exe_ToRemove" or "CuraEngine_exe_ToRemove" key then don't render anything (i.e. removing it from the output) -->
  35. <xsl:template match="*[ self::wix:Component or self::wix:ComponentRef ][ key( 'UltiMaker_Cura_exe_ToRemove', @Id ) ]"/>
  36. <xsl:template match="*[ self::wix:Component or self::wix:ComponentRef ][ key( 'CuraEngine_exe_ToRemove', @Id ) ]"/>
  37. </xsl:stylesheet>