Subject: RE: [xsl] Flattening a XML tree From: "Casadome, Francisco Javier" <Francisco.Casadome@xxxxxxxxxxxxxx> Date: Tue, 2 Oct 2001 08:30:03 +0200 |
Hi Farroq, Try this XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="no" indent="yes"/> <xsl:template match="/Tree"> <Tree> <xsl:for-each select="//TreeNode"> <xsl:sort select="@id" data-type="number"/> <xsl:element name="TreeNode"> <xsl:attribute name="id"> <xsl:value-of select="@id"/> </xsl:attribute> <xsl:attribute name="weight"> <xsl:value-of select="@weight"/> </xsl:attribute> </xsl:element> </xsl:for-each> </Tree> </xsl:template> </xsl:stylesheet> It will produce the following XML (don't know if this was exactly what you wanted): <?xml version="1.0" encoding="UTF-16"?> <Tree> <TreeNode id="1" weight="5"/> <TreeNode id="2" weight="3"/> <TreeNode id="3" weight="4"/> <TreeNode id="4" weight="2"/> <TreeNode id="5" weight="2"/> <TreeNode id="6" weight="2"/> <TreeNode id="7" weight="2"/> <TreeNode id="8" weight="2"/> <TreeNode id="9" weight="3"/> <TreeNode id="10" weight="2"/> <TreeNode id="11" weight="2"/> <TreeNode id="12" weight="2"/> </Tree> Cheers, Frank. -----Original Message----- From: Mir Farooq Ali [mailto:mfali@xxxxxxxxxxxxxxxx] Sent: martes, 02 de octubre de 2001 6:00 To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Flattening a XML tree Hi, I have an input tree that looks like this <?xml version="1.0"?> <Tree> <TreeNode id="1" weight="5"> <TreeNode id="2" weight="3"> <TreeNode id="6" weight="2"/> <TreeNode id="7" weight="2"/> <TreeNode id="8" weight="2"/> </TreeNode> <TreeNode id="3" weight="4"> <TreeNode id="9" weight="3"> <TreeNode id="11" weight="2"/> <TreeNode id="12" weight="2"/> </TreeNode> <TreeNode id="10" weight="2"/> </TreeNode> <TreeNode id="4" weight="2"/> <TreeNode id="5" weight="2"/> </TreeNode> </Tree> I need to flatten the tree to a structure that looks like this. I've looked at the archives, but haven't found an answer. <?xml version="1.0"?> <Tree> <TreeNode id="1" weight="5"> <TreeNode id="2" weight="3"/> <TreeNode id="3" weight="4"/> <TreeNode id="4" weight="2"/> <TreeNode id="5" weight="2"/> <TreeNode id="6" weight="2"/> <TreeNode id="7" weight="2"/> <TreeNode id="8" weight="2"/> <TreeNode id="11" weight="2"/> <TreeNode id="12" weight="2"/> <TreeNode id="9" weight="3"/> <TreeNode id="10" weight="2"/> </TreeNode> </Tree> Any help is appreciated. Thanks, -Farooq. +---------------------------------+-------------------------------------+ | Ph.D. Candidate | (540) 5520967 (R) (540) 2313986 (W)| | Department of Computer Science | Email: mfali@xxxxxx | | Virginia Tech. | Web: http://csgrad.cs.vt.edu/~mfali | +---------------------------------+-------------------------------------+ 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Flattening a XML tree, Mir Farooq Ali | Thread | RE: [xsl] Flattening a XML tree, Zwetselaar M. van (M |
Re: [xsl]: How to handle two XML so, Paul Tyson | Date | Re: [xsl] DTD for XSLT, Colin Paul Adams |
Month |