1

I have an XSL file that keeps coming up with the above error. Here is my code:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml"/>
    <xsl:template match="faculty">
        <xsl:element name='{fname}'>
            <xsl:for-each select="students/name">
                <name>
                    <xsl:value-of select="."/>
                </name>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

And here is part of my source XML file:

    <faculties xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
        xsi:noNamespaceSchemaLocation='257lab2a.xsd'>
        <faculty>
            <fname>literal arts</fname>
            <students>
                <name>ron dell</name>
                <mark>52</mark>
                <phone number='349-095-9867'></phone>
                <courseCategory category='full time'></courseCategory>
                <courseNo courseNumber='LART433'></courseNo>
            </students>
        </faculty>
    </faculties>
james.garriss
  • 12,959
  • 7
  • 83
  • 96
Kyle Wilson
  • 25
  • 1
  • 5
  • The most likely explanation is that there is no element named `fname` under one of your `faculty` elements, or `fname` is blank. Can you show us your input XML? – JLRishe Oct 15 '13 at 17:23

1 Answers1

1

It appears to be because fname contains text which is not a valid element name (can't contain a space). Try the following, but keep in mind there could other cases you need to address, depending on your data.

<xsl:template match="faculty">
    <xsl:element name="{translate(fname, ' ', '_')}">
        <xsl:for-each select="students/name">
            <name>
                <xsl:value-of select="."/>
            </name>
        </xsl:for-each>
    </xsl:element>
</xsl:template>
user2880616
  • 255
  • 3
  • 12