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

Re: XSL to create nested list items?

Subject: Re: XSL to create nested list items?
From: Shawn <sgrover@xxxxxxxxxxxxxx>
Date: Fri, 19 Nov 2004 03:56:43 -0700
xsl fo nested list
Thank you for the response Jarno.

I tried your template sample, but kept getting errors on the first 
xsl:template line.  That's PHP for you though, it's VERY picky I'm finding, 
and I don't see anything in the line that would trigger an error.

I did manage to resolve the problem though.  I took my clue from your "menu" 
template, and kicked myself for not seeing the simpler way sooner.  Instead 
of simply putting a new <item> element inside an existing one, I wrapped the 
sub-menu items in a <menu> element.  Then, with the XSL, I could write a 
template for the <menu> elements that would create the <ul> tags... er, 
here's the new xsl - I think it's easier to see what I did than me trying to 
explain it:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:template match="/">
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="menu">
		<ul>
			<xsl:apply-templates/>
		</ul>
	</xsl:template>
  
	<xsl:template match="item">
		<li>
			<a href="{url}">
				<xsl:value-of select="name"/>
			</a>
		</li>
		<xsl:apply-templates select="menu"/>
	</xsl:template>

</xsl:stylesheet>

with the xml looking like so:

<menu>
	<item>
		<name>Biographies</name>
		<url>#</url>
		<menu>
			<item>
				<name>Chatter Box</name>
				<url>#</url>
			</item>
		</menu>
	</item>
	<item>
		<name>Media</name>
		<url>#</url>
		<menu>
			<item>
				<name>Audio</name>
				<url>#</url>
				<menu>
					<item>
						<name>Song 1</name>
						<url>#</url>
					</item>
					<item>
						<name>Song 2</name>
						<url>#</url>
					</item>
				</menu>
			</item>
			<item>
				<name>Images</name>
				<url>#</url>
			</item>
		</menu>
	</item>	
</menu>

I'm getting the output I was after now.  Now I can focus on the CSS side of 
things and make my menu all pretty.. :)

Thanks again.

Shawn

On Friday 19 November 2004 02:59, Jarno.Elovirta@xxxxxxxxx wrote:
>   <xsl:template match="menu">
>     <html>
>       <head>
>         <title></title>
>       </head>
>       <body>
>         <ul>
>           <xsl:apply-templates select="item"/>
>         </ul>
>       </body>
>     </html>
>   </xsl:template>
>   <xsl:template match="item">
>     <li>
>       <a href="{url}">
>         <xsl:value-of select="name"/>
>       </a>
>       <xsl:if test="item">
>         <ul>
>           <xsl:apply-templates select="item"/>
>         </ul>
>       </xsl:if>
>     </li>
>   </xsl:template>
>
>
> But if you have multiple top-level items, do they all have @parent = 0? How
> do you know which item is inside which. I think you're better off using the
> earlier XML vocabulary. If you want to add numbering, add
>
>   <xsl:number level="multiple"/>
>
> as the first child of li element, just before a element.
>
> Cheers,
>
> Jarno

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.