【发布时间】:2019-07-28 19:25:29
【问题描述】:
我有如下 XSLT:-
<ServiceRequest ExternalSystemName="ServiceNow" Company="{ServiceRequest-Company}">
<xsl:if test="{ServiceRequest-LastResolvedDate} and {ServiceRequest-LastResolvedDate} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute name="LastResolvedDate">
<xsl:value-of select="{ServiceRequest-LastResolvedDate}" />
</xsl:attribute>
</xsl:if>
<xsl:if test="{ServiceRequest-ServiceType} and {ServiceRequest-ServiceType} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute name="ServiceType">
<xsl:value-of select="'SR'" />
</xsl:attribute>
</xsl:if>
...
...
我想通过 C# 代码重命名特定的属性名称。
为此我写了下面的代码:-
var property = root.Descendants(elementName).Descendants().Attributes("name").Where(x => x.Value == "LastResolvedDate");
foreach (var item in property)
{
item.Name = "renamed_new_name";
}
此代码给我的错误是属性名称无法分配并且是只读的。
可能的解决方案是什么?
编辑 1:
它正在更改属性名称:-
<xsl:if test="LastResolvedOn/value and LastResolvedOn/value != ''">
<xsl:attribute renamed_new_name="LastResolvedOn">
<xsl:value-of select="LastResolvedOn/value" />
</xsl:attribute>
</xsl:if>
我需要的地方:-
<xsl:if test="LastResolvedOn/value and LastResolvedOn/value != ''">
<xsl:attribute name="renamed_new_name">
<xsl:value-of select="LastResolvedOn/value" />
</xsl:attribute>
</xsl:if>
【问题讨论】: