Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set multiple attributes on root elemement using web.config transformation

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

like image 888
Johan Leino Avatar asked Jul 31 '12 08:07

Johan Leino


1 Answers

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>
like image 118
chrisp_68 Avatar answered Nov 15 '22 18:11

chrisp_68