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

Re: Creating Hierarchy

Subject: Re: Creating Hierarchy
From: "Rowan Sylvester-Bradley" <rowan@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Oct 2008 13:47:13 +0100
Re:  Creating Hierarchy
You'll find a description of an XSLT 2.0 stylesheet that does this (and some
other things besides) at


http://www.idealliance.org/proceedings/xml04/papers/111/mhk-paper.html

Michael Kay
http://www.saxonica.com/


Thanks to Michael and Ken for your replies. I've now got it more or less working using xsl:for-each-group. However, I've got another problem that I can't quite work out. Each of the main elements in the result file needs to have a unique ID attribute. So if my source file is:


<mytree>
  <node>
    <name>Root of my tree</name>
    <level>0</level>
  </node>
  <node>
    <name>Child of root</name>
    <level>1</level>
  </node>
  <node>
    <name>Another child of root</name>
    <level>1</level>
  </node>
  <node>
    <name>Grandchild of root</name>
    <level>2</level>
  </node>
  <node>
    <name>Yet another child of root</name>
    <level>1</level>
  </node>
</mytree>

I want to transform this into this:

<newnode id="1">
  <name>Root of my tree</name>
  <newnode id="2">
    <name>Child of root</name>
  </newnode>
  <newnode id="3">
    <name>Another child of root</name>
    <newnode id="4">
      <name>Grandchild of root</name>
    </newnode>
  </newnode>
  <newnode id="5">
    <name>Yet another child of root</name>
  </newnode>
</newnode>

I.e. the id attributes just keep incrementing regardless of the hierarchy.

How do I generate the values of these id attributes?

Thanks - Rowan

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.