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

Bread-crumbs nav from nested hierarchy in reverse orde

Subject: Bread-crumbs nav from nested hierarchy in reverse order
From: "Simerman, Joshua Michael" <jsimerma@xxxxxxxxxxx>
Date: Mon, 18 Aug 2003 22:51:50 -0500
nested hierarchy
I'm trying to create bread-crumbing for the navigation of a website. I
have the site hierarchy in a forwards nested document like below. The
only way I could figure out how to get the bread crumbs at all was to
get a backwards result. Once I have the result doc, I dump it as a
srting to the browser. Got any ideas of a simple way to reverse the
order in xsl, or a better way to write my first xsl?

Here's how my xml document is formed.

<page>
	<title>Home Page<title>
	<pageid>1</pageid>
	<page>
		<title>Parent Page</title>
		<pageid>2</pageid>
		<page>
			<title>This Page</title>
			<pageid>3</pageid>
		</page>
	<page>
</page>

Here's the xslt I wrote up.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:param name="pageid" select="23"/>
	<xsl:template match="/">
		<docroot>
			<xsl:apply-templates mode="first"/>
		</docroot>
	</xsl:template>
	<xsl:template match="node()" mode="first">
		<xsl:apply-templates select="page" mode="first"/>
		<xsl:if test="pageid=$pageid">
			<xsl:call-template name="bread-crumb"/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="node()" mode="ancestor">
		<xsl:call-template name="bread-crumb"/>
	</xsl:template>
	<xsl:template name="bread-crumb">
		<xsl:text>&gt;&gt;</xsl:text>
		<xsl:element name="a">
			<xsl:attribute
name="href">index.cfm?pageid=<xsl:value-of
select="pageid"/></xsl:attribute>
			<xsl:value-of
select="normalize-space(pagetitle)"/>
		</xsl:element>
		<xsl:if test="../pageid">
			<xsl:apply-templates select=".."
mode="ancestor"/>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

This is what I end up with.

<?xml version="1.0" encoding="UTF-8"?>
<docroot>
	<a href="index.cfm?pageid=23">Laptop Requirements</a>
	<a href="index.cfm?pageid=21">Computing</a>
	<a href="index.cfm?pageid=20">Once you're admitted</a>
	<a href="index.cfm?pageid=1">Admissions</a>
</docroot>

Here's the browser view.

>>Laptop Requirements>>Computing>>Once you're admitted>>Admissions



Josh Simerman
Graduate Assistant, Web Developer
Systems & Accounting Graduate Programs
Indiana University, Kelley School of Business


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.