ExcludeComponents.xslt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637
  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="ExeToRemove"
  20. match="wix:Component[ substring( wix:File/@Source, string-length( wix:File/@Source ) - 3 ) = '.exe' ]"
  21. use="@Id"
  22. /> <!-- Get the last 4 characters of a string using `substring( s, len(s) - 3 )`, it uses -3 and not -4 because XSLT uses 1-based indexes, not 0-based indexes. -->
  23. <!-- By default, copy all elements and nodes into the output... -->
  24. <xsl:template match="@*|node()">
  25. <xsl:copy>
  26. <xsl:apply-templates select="@*|node()"/>
  27. </xsl:copy>
  28. </xsl:template>
  29. <!-- ...but if the element has the "ExeToRemove" key then don't render anything (i.e. removing it from the output) -->
  30. <xsl:template match="*[ self::wix:Component or self::wix:ComponentRef ][ key( 'ExeToRemove', @Id ) ]"/>
  31. </xsl:stylesheet>