我有一段XML,其结构类似于:
<root>
<score name="Exam 1"><value>76</value></score>
<score name="Exam 2"><value>87</value</score>
</root>
我想把它变成这样:
<root>
<Exam 1>76</Exam 1>
<Exam 2>87</Exam 2>
</root>
this article
我正在使用此样式表:
<stylesheet>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='@*|node()'>
<xsl:copy>
<xsl:apply-templates select='@*|node()'/>
</xsl:copy>
</xsl:template>
<xsl:template match='score'>
<xsl:element name='{@name}'>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
</stylesheet>
System.Xml.Xslt.XsltException:“考试1”是无效的QName
谷歌的许多结果显示,有此错误的人不知何故传递了一个空字符串,错误是“”是一个无效的QName,但这里的情况并非如此。
有什么问题?有更好的替代方案吗?