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

Re: Generate Hierarchical Tree from non-hierarchical XML

Subject: Re: Generate Hierarchical Tree from non-hierarchical XML
From: Michal_Mart@xxxxxxxxxxx
Date: Thu, 17 Aug 2000 15:00:08 -0400
xml hierarchical tree

Hi,

This will generate (almost) the  output you require. I don't know if this is the
best way to achieve this output though.
Short explanation: Finds all top-level managers (those with an empty manager
element) output them , for each one find all of their subordinates output them
and recursively process their subordinates. There is also a helper (recursive)
template to output the indenting.
Your required tree listed John 3 before John 4 whereas this one will output John
4 first. I don't know if this makes a difference to you.

Hope this helps,
Michal


<xsl:template match="/">

<xsl:for-each select="employees/employee[manager='']">
     <xsl:value-of select="name"/>
     <xsl:call-template name="myEmployees">
          <xsl:with-param name="empid" select="./id"/>
          <xsl:with-param name="indent" select="0"/>
     </xsl:call-template>
</xsl:for-each>

</xsl:template>

<xsl:template name="myEmployees">
<xsl:param name="empid"/>
<xsl:param name="indent"/>
     <xsl:for-each select="/employees/employee[manager=$empid]">
          <BR/>
          <xsl:call-template name="Indenter">
               <xsl:with-param name="iIndent" select="$indent"/>
          </xsl:call-template>

          <xsl:value-of select="name"/>

          <xsl:call-template name="myEmployees">
          <xsl:with-param name="empid" select="./id"/>
          <xsl:with-param name="indent" select="$indent + 2"/>
          </xsl:call-template>

     </xsl:for-each>
</xsl:template>

<xsl:template name="Indenter">
     <xsl:param name="iIndent"/>
          <xsl:text>&#160;</xsl:text>
          <xsl:if test="$iIndent>0">

          <xsl:call-template name="Indenter">
               <xsl:with-param name="iIndent" select="$iIndent - 1"/>
          </xsl:call-template>

          </xsl:if>

</xsl:template>

</xsl:stylesheet>


Tested and works with IE5 July parser.




Dawinder Khehra <dskhehra@xxxxxxxxx> on 08/17/2000 11:13:23 AM

Please respond to xsl-list@xxxxxxxxxxxxxxxx

To:   xsl-list@xxxxxxxxxxxxxxxx
cc:    (bcc: Michal Mart)

Subject:  Generate Hierarchical Tree from non-hierarchical XML




Here is the XML

<employees>
   <employee>
      <id>1</id>
      <name>John 1</name>
      <manager/>
   </employee>
   <employee>
      <id>4</id>
      <name>John 4</name>
      <manager>1</manager>
   </employee>
   <employee>
      <id>3</id>
      <name>John 3</name>
      <manager>1</manager>
   </employee>
   <employee>
      <id>2</id>
      <name>John 2</name>
      <manager>3</manager>
   </employee>
</employees>

Output needed is
John 1
   John 3
      John 2
   John 4

Please help in writing XSL for ie5.

Thanks!

__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/


 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.