xsl-list
[Top] [All Lists]

RE: XSL to create nested list items?

2004-11-19 04:27:27
Hi,

I tried your template sample, but kept getting errors on the first 
xsl:template line.

Was the xsl:template the first element in the file? You have to use 
xsl:stylesheet as the root element, I just omitted it for brevity.

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"/>

This xsl:apply-templates should be inside the above li element, right after the 
a element. That way you get valid XHTML.

Cheers,

Jarno

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--