使用web在根元素上设置多个属性。配置转换

时间:2022-06-06 11:26:18

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.

在visual studio(web。我有一个要执行的转换,它在根元素上添加两个属性。一个attrbute起作用(但不是多个)。我可以在子元素上设置多个属性。我尝试了SetAttributes,但没有指定属性的名称,没有运气。

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:

“元素”部分实际上是web的自定义部分。配置文件…像这样:

<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

一旦根元素上有超过1个属性,它就失败了。

2 个解决方案

#1


6  

Have you tried a transform like this that sets multiple attributes at the same time by passing a list of attributes to set to SetAttribute()?

您是否尝试过这样的转换,通过将属性列表设置为SetAttribute()来同时设置多个属性?

See here form more info.

更多信息请参见这里。

Secifically: Transform="SetAttributes(comma-delimited list of one or more attribute names)"

seci: Transform="SetAttributes(一个或多个属性名的逗号分隔列表)"

<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>

#2


0  

The document element of a web.config file is <configuration>. In your example, <element> is probably a child of <configuration>. Try:

web的文档元素。配置文件是 <配置> 。在您的示例中, 可能是 的子元素。试一试:

<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>

#1


6  

Have you tried a transform like this that sets multiple attributes at the same time by passing a list of attributes to set to SetAttribute()?

您是否尝试过这样的转换,通过将属性列表设置为SetAttribute()来同时设置多个属性?

See here form more info.

更多信息请参见这里。

Secifically: Transform="SetAttributes(comma-delimited list of one or more attribute names)"

seci: Transform="SetAttributes(一个或多个属性名的逗号分隔列表)"

<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>

#2


0  

The document element of a web.config file is <configuration>. In your example, <element> is probably a child of <configuration>. Try:

web的文档元素。配置文件是 <配置> 。在您的示例中, 可能是 的子元素。试一试:

<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>