|
next
|
 Subject: Creating HTML Unordered LIsts. HELP! Author: Ben Babics Date: 27 Apr 2009 07:02 AM Originally Posted: 26 Apr 2009 10:53 PM
|
Hello,
I'm having a bit of trouble with this one. Although, I'm sure it may not be too difficult for some XSL guru's. Anyways, I'm hoping I can get some answers; any help is much appreciated. :)
I'm working on a project where I need a navigation (2-tier, sub-menu's etc.), a sectional navigation on each page (this is for user's who have JavaScript disabled and need to view the submenu for the section relative to the page their currently on), a footer and a sitemap.
I decided to circumvent a maintenance nightmare by using a single XML file to hold the data and write XSL Style Sheets for each section: navigation.xsl, subnav.xsl (subnavigation on each page), footer.xsl and sitemap.xsl. Hopefully you're still with me.
Really each XSL will be generating an HTML unordered list(s), but each list will be slightly different from the other list(s)- there in lies the problem. :)
***********************
**** site_data.xml ****
***********************
<sitemap>
<pages>
<page title="Home" src="/www/" />
<page title="Business" src="/www/business/">
<pages>
<page title="Business 1" src="business1.html" />
<page title="Business 2" src="business2.html" />
</pages>
</page>
</pages>
<page title="About Us" src="/www/about/">
<pages>
<page title="About 1" src="about1.html" />
<page title="About 2" src="about2.html" />
</pages>
</page>
<page title="Contact Us" src="/www/contact/" />
</pages>
</sitemap>
The issue I'm having is that for the navigation, I need to derive two unordered lists from this. The first: Home and Business. The second: About Us and Contact Us.
**********************
****navigation.xsl****
**********************
<xsl:template match="pages">
<xsl:choose>
<xsl:when test="page[@title = 'About Us' or @title = 'Contact Us']">
<ul>
<xsl:apply-templates select="page" />
</ul>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:apply-templates select="page" />
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="page">
<xsl:variable name="path">
<xsl:value-of select="../../@src" /><xsl:value-of select="@src" />
</xsl:variable>
<li>
<a href="{$path}"><xsl:value-of select="@title" /></a>
<xsl:apply-templates select="pages" />
</li>
</xsl:template>
You'll notice that I am traversing the node list to do proper nesting. However, I'm having a very difficult time determining how to initially create two separate unordered lists and have the proper nodes be populated within their respective list.
PLEASE HELP!!! :)
Thanks,
Ben
site_data.xml site_data.xml
navigation.xsl navigation.xsl
|
|
|