Topic: XML file to 'nested' list? Pages that link to <a href="https://ozoneasylum.com/backlink?for=11123" title="Pages that link to Topic: XML file to &amp;#039;nested&amp;#039; list?" rel="nofollow" >Topic: XML file to &#039;nested&#039; list?\

 
Author Thread
Kaniz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

IP logged posted posted 01-02-2004 06:13 Edit Quote

I have an xml file that is something like

code:
<menu>
<menuitem>
<name>Products</name>
<link>#</link>
<menuitem>
<name>Printing</name>
<link>#</link>
</menuitem>
<menuitem>
<name>Whatever</name>
<link>#</link>
<menuitem>
<name>Whatever-Sub</name>
<link>#</link>
</menuitem>

</menuitem>

</menuitem>
</menuitem>



How could I break this down into a menu structure like

-Products
---Printing
---Whatever
------Whatever-Sub
---Something
------Something1
---------Something2
---------Whateverblah

What I have so far, is something along the lines of

code:
<xsl:for-each select="menu/menuitem">

</xsl:for-each>
<script>
var oMenu1 = new Menu();
<xsl:for-each select="menu/menuitem">
<xsl:if test="count(menuitem) = 0">
var oMenu1A = oMenu1.CreateLink();
oMenu1A.displayHtml = "<xsl:value-of select="name" />";
oMenu1A.href = "<xsl:value-of select="link" />";
</xsl:if>
<xsl:if test="count(menuitem) > 0">


var oMenu1B = oMenu1.CreateMenu();
oMenu1B.displayHtml = "<xsl:value-of select="name" />";
<xsl:for-each select="menuitem">
var oMenu1B_a = oMenu1.CreateLink();
oMenu1B_a.displayHtml = "<xsl:value-of select="name" />";
oMenu1B_a.href = "<xsl:value-of select="link" />";
oMenu1B.AddItem(oMenu1B_a);

</xsl:for-each>
oMenu1.AddItem(oMenu1B);
</xsl:if>
<xsl:if test="count(menuitem) = 0">
oMenu1.AddItem(oMenu1A);
</xsl:if>
</xsl:for-each>



However, for each 'level' of nesting I want to be able to handle, it seems like I need to do another for-each. While my current use for this is only going to have maybe 3 levels tops, its not that bad. My worry is if it needs to get any bigger, I dont want to keep adding level after level of for-each.


Moon Shadow
Paranoid (IV) Inmate

From: Rouen, France
Insane since: Jan 2003

IP logged posted posted 01-03-2004 17:06 Edit Quote

First, I must say I don't understand much of your XSL code, so forgive me if I say something idiotic. I was wondering, wouldn't it be easier to create nested lists like this ?

code:
<ul>

<xsl:for-each select="menu/menuitem">

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

</xsl:for-each>

</ul>
....
</ul>
</ul>

(write he number of </ul> you need)



Kaniz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

IP logged posted posted 01-04-2004 22:37 Edit Quote

I tried simply doing the for-each menuitem/menu thing, but it'd only do it for 1 layer. If any menu option had sub-options, it wasnt working.

MajorFracas
Nervous Wreck (II) Inmate

From:
Insane since: Jul 2003

IP logged posted posted 01-15-2004 18:07 Edit Quote

Could you post a sample source file and the complete XSLT file? I can see some places where there might be problems but wouldn't know for sure unless I could test it...



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu