I have a piece of XML that is structured similar to this:
<root> <score name="Exam 1"><value>76</value></score> <score name="Exam 2"><value>87</value</score> </root>
and I would like to transform it to look like this:
<root>
<Exam 1>76</Exam 1>
<Exam 2>87</Exam 2>
</root>
Following this article I am using this stylesheet:
<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>
However, when I transform it and load it into a document, I receive this error:
System.Xml.Xslt.XsltException: 'Exam 1' is an invalid QName
It seems that many of the google results show people with this error have passed an empty string somehow, the error is "" is an invalid QName, but that's not the case here.
What is the problem? Is there a better, alternative solution?
From stackoverflow
-
You cannot have a space in an element name.
pc1oad1etter : Yep, that was it.
0 comments:
Post a Comment