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

RE: HOWTO: convert flat list w/ level information to

Subject: RE: HOWTO: convert flat list w/ level information to a hierarchial one?
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 2 Dec 2003 12:46:45 -0000
flat list
The general solution to this kind of problem is to use
<xsl:apply-templates> on each node, in the normal, way, except that
instead of selecting the physical children of a node, you select the
logical children. In your case the logical children are obtained by

<xsl:variable name="this" select="."/>
<xsl:apply-templates
select="following-sibling::node[@level=$this/@level+1 and
          generate-id($this) =
generate-id(preceding-sibling::node[@level=$this/@level]]"/>

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Marcus Zelezny
> Sent: 02 December 2003 10:41
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  HOWTO: convert flat list w/ level information 
> to a hierarchial one?
> 
> 
> Dear XSLT Community!
> 
> I couldn't solve a problem of class "flat file transform".
> 
> From (@name, just for illustration) flat file with @level 
> information: <node>  <node level="0" type="c" 
> name="toplevel"/>  <node level="1" type="i" name="1. item"/>  
> <node level="1" type="c" name="2. container"/>  <node 
> level="2" type="i" name="2.1 item"/>  <node level="2" 
> type="i" name="2.2 item"/>  <node level="1" type="i" name="3. 
> item"/><!-- implicit close of previous container -->  <node 
> level="1" type="c" name="4. container"/>  <node level="2" 
> type="i" name="4.1 item"/>  <node level="2" type="c" 
> name="4.2 container"/>  <node level="3" type="i" name="4.2.1 
> item"/> </node>
> <!--
> @type = 'c' ... container
> @type = 'i' ... Item
> -->
> 
> transform to:
> <node>
>  <node type="c" name="toplevel">
>   <node type="i" name="1. item"/>
>   <node type="c" name="2. container"/>
>    <node type="i" name="2.1 item"/>
>    <node type="i" name="2.2 item"/>
>   </node>
>   <node type="i" name="3. item"/>
>   <node type="c" name="4. container">
>    <node type="i" name="4.1 item"/>
>    <node type="c" name="4.2 container"/>
>     <node type="i" name="4.2.1 item"/>
>    </node>
>   </node>
>  </node>
> </node>
> 
> What I tried:
> Calling recursively a template with passing parameters $node, 
> $last-level, but I failed to leave recursion in a proper way;-(
> 
> Any pointer|hint|solution for a (ideally) XSLT1.0 approach is 
> highly appreciated!
> 
> Thanks in advance
> 	     Marcus
> 
> P.S. I read http://www.dpawson.co.uk/xsl/sect2/flatfile.html
> 
>  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

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.