【发布时间】:2015-04-16 10:12:45
【问题描述】:
我有一个 XML 输入,其中的元素具有许多属性。我事先不知道,哪些属性。
我想为每个现有属性创建一个同名的属性元素。
输入:
<elem id="1" name="test" version="2" />
<elem id="2" check="true" base="dir"/>
输出:
<newelem newattribute="bla" newattribute2="blabla" id="1" name="test" version="2"/>
<newelem newattribute="bla" newattribute2="blabla" id="2" check="true" base="dir"/>
我试过了:
<xsl:for-each select="@*">
<xsl:attribute name="name(.)" select="."/>
</xsl:for-each>
但是 name() 函数似乎在这里不起作用。
这样做的正确方法是什么?
【问题讨论】: