Invalid QName while transforming .net XSLTransform

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 convert it 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 convert it and load it into a document, I get this error:

System.Xml.Xslt.XsltException: "Exam 1" is an invalid QName

It looks like many of the google results show that people with this error passed in an empty string somehow, the error "" is an invalid QName, but it isn't.

What is the problem? Is there a better alternative solution?

+1


source to share


1 answer


You cannot have a space in the element name.



+1


source







All Articles