In visual studio (web.config transformations) I have a transformation I want to perform which adds two attributes on the root element. One attrbute works (but not multiple ones). And I can set multiple attributes on a child element. I have tried SetAttributes with and without specifying the names of the attributes, no luck.
Ideas??
example
<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two">
<children>
<child name="One" xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two" />
</children>
</element>
desired effect
<element attrOne="One" attrTwo="Two">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>
The "element" section is really a custom section of the web.config file...like so:
<configuration>
... <element configSource="App_Data\element.config" />
this transformation is meant to be used on the element.config file (using slow cheetah)
Update This apparently doesn't work either:
<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace" attrOne="One" attrTwo="Two">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>
But this does:
<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace" attrOne="One">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>
As soon as there are more than 1 attribute on the root element it fails
Have you tried a document transform like this that sets multiple attributes at the same time by passing a list of attributes to set to SetAttribute()
?
See here form more info.
Specifically: Transform="SetAttributes(comma-delimited list of one or more attribute names)"
<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes(attrOne,attrTwo)" attrOne="One" attrTwo="Two">
<children>
<child name="One" xdt:Transform="SetAttributes(attrOne,attrTwo)" attrOne="One" attrTwo="Two" />
</children>
</element>
The document element of a web.config
file is <configuration>
. In your example, <element>
is probably a child of <configuration>
. Try:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<element xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two">
<children>
<child xdt:Transform="SetAttributes" name="One"
attrOne="One" attrTwo="Two" />
</children>
</element>
</configuration>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.