XSLT:如何在 <xsl:copy> 期间更改属性值? [英] XSLT: How to change an attribute value during <xsl:copy>?
本文介绍了XSLT:如何在 <xsl:copy> 期间更改属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 XML 文档,我想更改其中一个属性的值.
I have an XML document, and I want to change the values for one of the attributes.
首先,我使用以下方法复制了从输入到输出的所有内容:
First I copied everything from input to output using:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
现在我想在任何名为 "property"
的元素中更改属性 "type"
的值.
And now I want to change the value of the attribute "type"
in any element named "property"
.
推荐答案
在一个简单的例子上测试,工作正常:
Tested on a simple example, works fine:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@type[parent::property]">
<xsl:attribute name="type">
<xsl:value-of select="'your value here'"/>
</xsl:attribute>
</xsl:template>
编辑以包含 Tomalak 的建议.
Edited to include Tomalak's suggestion.
这篇关于XSLT:如何在 <xsl:copy> 期间更改属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文