5

In visual studio (trasformazioni web.config) Ho una trasformazione che desidero eseguire che aggiunge due attributi all'elemento radice. Un attrbute funziona (ma non multipli). E posso impostare più attributi su un elemento figlio. Ho provato SetAttributes con e senza specificare i nomi degli attributi, senza fortuna.Impostare più attributi sull'edema radice utilizzando la trasformazione web.config

Idee ??

esempio

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

effetto desiderato

<element attrOne="One" attrTwo="Two"> 
     <children> 
     <child name="One" attrOne="One" attrTwo="Two" /> 
     </children> 
    </element> 

La sezione "elemento" è in realtà una sezione personalizzata del file web.config ... in questo modo:

<configuration> 

... <element configSource="App_Data\element.config" /> 

questo t ransformation è pensato per essere utilizzato sul file element.config (usando lenta ghepardo)

Aggiornamento Questo a quanto pare non funziona neanche:

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

Ma questo fa:

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

Non appena ci sono più di 1 attributo sull'elemento radice fallisce

risposta

0

L'elemento documento di un 012 Il fileè <configuration>. Nel tuo esempio, <element> è probabilmente un figlio di <configuration>. Prova:

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

dispiace, voleva dire che non è il file web.config è di per sé, ma questo mostra una sezione personalizzata di esso. È comunque interessante che SetAttributes funzioni con un attributo ma non con due ... sull'elemento radice –

6

Hai provato una trasformazione come questo che mette più attributi contemporaneamente passando un elenco di attributi da impostare per SetAttribute()?

Vedere here form ulteriori informazioni.

Secifically: Transform = "SetAttributes (elenco separato da virgole di uno o più nomi di attributi)"

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