RE: [xsl] changing node names in XML

Subject: RE: [xsl] changing node names in XML
From: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Fri, 25 Oct 2002 13:33:24 -0400
I'm sure there are better ways ... but this came to mind first:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
   <Employees>
     <xsl:apply-templates select="*"/>
   </Employees>
</xsl:template>
<xsl:template match="employee[count(child::*)&gt;0]">
	<folder>
		<xsl:copy-of select="attribute::*"/>
		<xsl:apply-templates select="*"/>
	</folder>
</xsl:template>
<xsl:template match="employee[count(child::*)=0]">
	<leaf>
		<xsl:copy-of select="attribute::*"/>
		<xsl:apply-templates select="*"/>
	</leaf>
</xsl:template>
</xsl:stylesheet>

HTH,
Jeff

-----Original Message-----
From: Vijay Mummaneni [mailto:vijaya.mummaneni@xxxxxxx]
Sent: Friday, October 25, 2002 1:13 PM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] changing node names in XML



Hi,

I need to change the node names in my XML file based on a condition.
If a an element has children then the element name has to become
"folder",
and if an element has no children then its name has to become "leaf".
For example :

<Employees>
       <employee name="emp5" id="5">
              <employee name="emp2" id="2">
                     <employee name="emp1" id="1"/>
                     <employee name="emp4" id="4"/>
            </employee>
            <employee name="emp3" id="3"/>
       </employee>
</Employees>


As :

<Employees>
       <folder  name="emp5" id="5">
              <folder  name="emp2" id="2">
                     <leaf  name="emp1" id="1"/>
                     <leaf  name="emp4" id="4"/>
            </folder>
            <leaf  name="emp3" id="3"/>
       </folder>
</Employees>

I wanted to use XSLT. Do you have a hint how can I achieve that ?

Thanks
vijay



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread