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

Generating a tree

Subject: Generating a tree
From: Marcus Andersson <marcus@xxxxxxxxxx>
Date: Tue, 04 May 2004 22:16:24 +0200
generating a tree
Hi gurus

I want to generate an "unfolded" tree down to a selected element. So I want to render all ancestors to the selected element and all their siblings but not the siblings children. Also, the root shouldn't be included and I don't want the siblings to the top-level (below the root element) ancestor to be included. Another wish is that if the selected element is a section element I also want to render it's children (just one level though).

Example source XML:

<site>
  <section name="level1_1">
    <section name="level2_1>
      <page name="level3_1"/>
    </section>
    <section name="level2_2"/>
    <page name="level2_3"/>
    <page name="level2_4"/>
    <section name="level2_5">
      <section name="level3_1">
        <page name="level4_1"/>
      </section>
      <page name="level3_2"/>
      <section name="level3_3"> <-- Selected element
        <page name="level4_1"/>
        <page name="level4_2"/>
      </section>
      <page name="level3_4"/>
    </section>
  </section>
  <page name="level1_2"/>
  <section name="level1_3">
    ...
  </section>
</site>

Wanted result (with indents and everything :) :
node name="level1_1"
  node name="level2_1"
  node name="level2_2"
  node name="level2_3"
  node name="level2_4"
  node name="level2_5"
    node name="level3_1"
    node name="level3_2"
    node name="level3_3"
      node name="level4_1" //shouldn't be rendered if page
      node name="level4_2" //shouldn't be rendered if page
    node name="level3_4"

It would also be nice if one could draw something extra to indicate whether the node has children or not (like a plus or minus...).

How would you do it? I've made a couple of tries with anscestor-or-self::etc but I just tangle myself into hairy loops.

The template/templates that will do this will be called on the selected element level.

/Marcus

ps. I'm using MSXML so node-set() is available.

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.