How can I use XSL to promote/demote elements in my XML file?

Viewed 37

I have an XML file here:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" version="1.0" href="test.xsl"?>
<class>
    <student>
        <name>Ben</name>
        <age></age>
        <ages></ages>
        <entryprofile></entryprofile>
    </student>
    <student>
        <name>Steve</name>
        <age></age>
        <ages></ages>
        <entryprofile></entryprofile>
    </student>
</class>

I am trying to promote the entryprofile element so that it becomes a child element of student, rather than an attribute of student. In other words, I am trying to 'demote' it. I have tried to apply the following XSL in order to do this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:xml-stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="X">
  <xsl:copy-of select="name, age, ages"/>
  <new-level>
     <xsl:copy-of select="entryprofile"/>
  </new-level>
</xsl:template>
</xsl:xml-stylesheet>

This doesn't seem to be doing much apart from create a blank page in my browser that simply says: 'Ben Steve'.

Would anyone know where I am going wrong, and what I can do to achieve my desired result? Many thanks.

0 Answers
Related