I\'m using web.config transformation as described in the below post in order to generate configs for different environments.
http://vishaljoshi.blogspot.com/2009/03/
A better method for me was to insert the element only if it doesn't exist since I am only setting certain attributes. Removing the element would discard any other attributes of the main element if they existed.
example: web.config (without element)
web.config (with element)
Using the Locator with an XPath expression, I add the node if it doesn't exist and then set my attribute:
both resulting web.config files have includeExceptionDetailInFaults="true" and the second one preserves the httpsHelpPageEnabled attribute where the remove/insert method would not.