- There are two attributes from the xdt namespace that are used in the transformation:
- The
Locator
attribute specifies how the element to be changed will be found.
- If you do not specify a Locator attribute, the element to be changed is specified implicitly by the element that the Transform attribute is specified for.
- There are three locator types:
Condition
: an XPath expression that is evaluated relative to the current element.
Match
: given a comma separated list of attribute names, will apply the transformation on elements whose attribute values match all of them.
XPath
: Specifies an absolute XPath expression that is applied to the development Web.config file.
- Unlike Condition, the expression that you specify is not appended to the implicit XPath expression that corresponds to the current element.
- The
Transform
element specifies what is done with the element once we have it.
<connectionStrings>
<add name="ConnectionName1" connectionString="newstring" providerName="newprovider"
xdt:Locator="Condition(@name='oldname' or @providerName='oldprovider')" xdt:Transform="Replace" />
<add name="ConnectionName2" connectionString="newstring" providerName="newprovider"
xdt:Locator="Match(name)" xdt:Transform="Replace" />
<add name="ConnectionName3" connectionString="newstring" providerName="newprovider"
xdt:Locator="XPath(configuration/connectionStrings[@name='ConnectionName3'
or @providerName='System.Data.SqlClient'])" xdt:Transform="Replace" />
</connectionStrings>
Transform Types
Replace
: Replaces the selected element with the element that is specified in the transform file.
- If more than one element is selected, only the first selected element is replaced.
Insert
: Adds the element that is defined in the transform file as a sibling to the selected element or elements.
- The new element is added at the end of any collection.
InsertIfMissing
InsertBefore
InsertAfter
Remove
: Removes the selected element. If multiple elements are selected, removes the first element.
RemoveAttributes
: Removes specified attributes from the selected elements.
SetAttributes
: Sets attributes for selected elements to the specified values.
- The
SetAttributes
attribute enables you to leave the element as it is but change selected attributes.
- If you do not specify which attributes to change, all of the attributes that are present in the element in the transform file are changed.
- The
SetAttributes
transform affects all selected elements.