Входной XML:XSL и добавить новый атрибут
<a>
<b1>
<c1 width="500" height="200">
<d1 data="null" />
</c1>
</b1>
<b2 />
</a>
Я хочу копию все атрибуты из b1/c1
в b2/c1
Идобавить новый атрибут (length
). Вывод XML должен быть:
<a>
<b1>
<c1 width="500" height="200">
<d1 data="null" />
</c1>
</b1>
<b2>
<c1 width="500" height="200" length="2">
<d1 data="null" />
</c1>
</b2>
</a>
У меня есть код, который скопировать все от b1/с1 до b2/с2, НО без добавления нового atttribute (length
):
<xsl:template match="https://stackoverflow.com/a/b2">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:copy-of select="https://stackoverflow.com/a/b1/c1" />
<xsl:apply-templates select="*" />
</xsl:copy>
</xsl:template>
И я попробовал добавить атрибут к копии, но он не работает:
<xsl:template match="https://stackoverflow.com/a/b2">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:copy-of select="https://stackoverflow.com/a/b1/c1" >
<xsl:attribute name="length">2</xsl:attribute>
</xsl:copy-of>
<xsl:apply-templates select="*" />
</xsl:copy>
</xsl:template>
извините, я редактировал входной XML: нет c1 в b2, поэтому мне нужно-копия из. так как это сделать сейчас? – victorio
отредактировали мой ответ. –
спасибо, ты спас мою перевозчика! – victorio