Altova Mailing List Archives


Re: [xsl] How to make tree menu from flat XML

From: "Mukul Gandhi" <gandhi.mukul@--------->
To:
Date: 7/22/2006 5:23:00 PM
Perhaps something like this could get you started:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>
	
<xsl:template match="/records">
 <xsl:for-each select="record[keynum &lt; -100]">
   <record keynum="{keynum}">
     <xsl:variable name="key1" select="keynum" />
     <xsl:for-each select="../record[(keynum &gt;= -50) and (keynum
&lt;= 0) and (parentkeynum = $key1)]">
       <xsl:variable name="key2" select="keynum" />
       <record keynum="{keynum}">
         <xsl:for-each select="../record[(keynum &gt; 0) and
(parentkeynum = $key2)]">
           <record keynum="{keynum}">

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

Regards,
Mukul

http://gandhimukul.tripod.com



On 7/22/06, Radoslav Kolarov <roonex@xxxxxxxxx> wrote:
Hi, I have this XML, and I want to make tree menu. The
roots elements of tree menu are the records with
keynum < -100, the children of the root elements are
records with keynum between -50 and 0 and
parentkeynum=keynum of the root, and the third level
of the tree menu are records with keynum > 0, and the
parentnumber shows the keynum of their parent. Please
help me.
XML file:


<?xml version="1.0" ?>
- <records>
- <record>
 <keynum>-1</keynum>
 <keyname>2 CLIENTS HAVE A NEGATIVE BALANCE</keyname>

 <parentkeynum>-100000</parentkeynum>
 <rowcnt>2</rowcnt>
 <balance>0</balance>
 </record>
- <record>
 <keynum>35</keynum>
 <keyname>35 MR. MICHAEL NOLAN</keyname>
 <parentkeynum>-1</parentkeynum>
 <rowcnt>1</rowcnt>
 <balance>-275</balance>
 </record>
- <record>
 <keynum>142</keynum>
 <keyname>142 MR. JOHN CALINSKI</keyname>
 <parentkeynum>-1</parentkeynum>
 <rowcnt>1</rowcnt>
 <balance>-11</balance>
 </record>
- <record>
 <keynum>-3</keynum>
 <keyname>42 CLIENTS CREDIT IS GREATER THAN
BALANCE</keyname>
 <parentkeynum>-100000</parentkeynum>
 <rowcnt>42</rowcnt>
 <balance>0</balance>
 </record>
- <record>
 <keynum>18</keynum>
 <keyname>18 MRS. LYNN BONIN</keyname>
 <parentkeynum>-3</parentkeynum>
 <rowcnt>1</rowcnt>
 <balance>0</balance>
 </record>
- <record>
 <keynum>35</keynum>
 <keyname>35 MR. MICHAEL NOLAN</keyname>
 <parentkeynum>-3</parentkeynum>
 <rowcnt>1</rowcnt>
 <balance>-275</balance>
 </record>
- <record>
 <keynum>43</keynum>
 <keyname>43 MR. JAMES D. NEFF</keyname>
 <parentkeynum>-3</parentkeynum>
 <rowcnt>1</rowcnt>
 <balance>0</balance>
 </record>
.................
.................
.................
- <record>
 <keynum>10006</keynum>
 <keyname>10006 MR. DALE SPONSEL 2003-04-24</keyname>

 <parentkeynum>-16</parentkeynum>
 <rowcnt>1</rowcnt>
 <balance>0</balance>
 </record>
- <record>
 <keynum>-100003</keynum>
 <keyname>APPOINTMENT ALERTS (1)</keyname>
 <parentkeynum>0</parentkeynum>
 <rowcnt>1</rowcnt>
 <balance>0</balance>
 </record>
- <record>
 <keynum>-100002</keynum>
 <keyname>HAIR SYSTEM ALERTS (2)</keyname>
 <parentkeynum>0</parentkeynum>
 <rowcnt>2</rowcnt>
 <balance>0</balance>
 </record>
- <record>
 <keynum>-100001</keynum>
 <keyname>PROGRAM ALERTS (2)</keyname>
 <parentkeynum>0</parentkeynum>
 <rowcnt>2</rowcnt>
 <balance>0</balance>
 </record>
- <record>
 <keynum>-100000</keynum>
 <keyname>FINANCIAL ALERTS (5)</keyname>
 <parentkeynum>0</parentkeynum>
 <rowcnt>5</rowcnt>
 <balance>0</balance>
 </record>
 </records>

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.