[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Flattening a XML tree

Subject: RE: Flattening a XML tree
From: "Zwetselaar M. van (Marco)" <Marco.van.Zwetselaar@xxxxxxxxxxxxx>
Date: Tue, 2 Oct 2001 09:19:08 +0200
treenode treenode
Farooq wrote:
> 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>  

Why would you expect to find an answer in the archives? It looks like any
other XSLT problem to me. And the way it usually is with problems, you need
to do some thinking  to solve them.

  <xsl:template match="Tree">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="Tree/TreeNode">
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="TreeNode">
    <xsl:copy>
      <xsl:copy-of select="@*" />
    </xsl:copy>
    <xsl:apply-templates />
  </xsl:template>

Regards,
Marco

DISCLAIMER: I have no control over the following disclaimer,
            my company puts it there.


***************************DISCLAIMER***********************************
Deze e-mail is uitsluitend bestemd voor de geadresseerde(n). 
Verstrekking aan en gebruik door anderen is niet toegestaan.
Fortis sluit iedere aansprakelijkheid uit die voortvloeit uit
electronische verzending.

This e-mail is intended exclusively for the addressee(s), and may
not be passed on to, or made available for use by any person 
other than the addressee(s).
Fortis rules out any and every liability resulting from any
electronic transmission.
************************************************************************

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.