Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / XML

Configuration By Environment

Rate me:
Please Sign up or sign in to vote.
3.42/5 (6 votes)
4 Jun 2008CPOL3 min read 30.3K   72   20  
Automated method for controlling the contents of application config files based on target environment
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" encoding="utf-8" />

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

  <xsl:template match="connectionStrings">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
      <add name="Northwind" connectionString="Data Source=ProdServer;Initial Catalog=Northwind;Integrated Security=True"
        providerName="System.Data.SqlClient" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="appSettings">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
      <add key="Salutation" value="Greetings from the RELEASE environment"/>
    </xsl:copy>
  </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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions