在visual studio(web.config转换)中,我有一个我想要执行的转换,它在根元素上添加了两个属性。一个attrbute工作(但不是多个)。我可以在子元素上设置多个属性。我已尝试使用和不指定属性名称的SetAttributes,没有运气。
想法?
例
<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>
期望的效果
<element attrOne="One" attrTwo="Two">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>
“element”部分实际上是web.config文件的自定义部分......就像这样:
<configuration>
... <element configSource="App_Data\element.config" />
这个转换意味着在element.config文件中使用(使用慢速猎豹)
更新这显然不起作用:
<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>
但这样做:
<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>
只要根元素上有多个属性,它就会失败
您是否尝试过这样的文档转换,通过将属性列表设置为SetAttribute()
来同时设置多个属性?
请参阅here表格了解更多信息。
具体来说: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>
web.config
文件的文档元素是<configuration>
。在你的例子中,<element>
可能是<configuration>
的孩子。尝试:
<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>