Click here to Skip to main content
15,886,199 members
Articles / Windows Installer

Creating a Localized Windows Installer & Bootstrapper: Part 2

Rate me:
Please Sign up or sign in to vote.
4.17/5 (3 votes)
25 Feb 2013CPOL4 min read 35.2K   165   13  
This series of articles is a complete end-to-end solution for building a localizable Windows Installer & Bootstrapper using some real-world requirements.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
  xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">

  <xsl:output method="xml" encoding="UTF-8" indent="yes" />

    <xsl:template match="wix:Wix">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="wix:Component/wix:File[substring(@Source,string-length(@Source)-3)='.dll' or substring(@Source,string-length(@Source)-3)='.exe']">
	<xsl:variable name="lastslashindex">
		<xsl:call-template name="lastIndexOf">
			 <xsl:with-param name="string" select="@Source" />
			 <xsl:with-param name="char" select="'\'" />
		 </xsl:call-template>
	</xsl:variable>

	<xsl:copy>
      <xsl:apply-templates select="@*" />
      <netfx:NativeImage Priority="1">
		<xsl:attribute name="Id">
			<xsl:value-of select="$lastslashindex"/>
		</xsl:attribute>
	   </netfx:NativeImage>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>
  
  <xsl:template name="lastIndexOf">
   <!-- declare that it takes two parameters - the string and the char -->
   <xsl:param name="string" />
   <xsl:param name="char" />
   <xsl:choose>
      <!-- if the string contains the character... -->
      <xsl:when test="contains($string, $char)">
         <!-- call the template recursively... -->
         <xsl:call-template name="lastIndexOf">
            <!-- with the string being the string after the character
                 -->
            <xsl:with-param name="string"
                            select="substring-after($string, $char)" />
            <!-- and the character being the same as before -->
            <xsl:with-param name="char" select="$char" />
         </xsl:call-template>
      </xsl:when>
      <!-- otherwise, return the value of the string -->
      <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
   </xsl:choose>
</xsl:template>
  
</xsl:stylesheet>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
Mike Carlisle - Technical Architect with over 20 years experience in a wide range of technologies.

@TheCodeKing

Comments and Discussions