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

RE: Bread-crumbs nav from nested hierarchy in reverse

Subject: RE: Bread-crumbs nav from nested hierarchy in reverse order
From: Armen Martirossian <armmarti@xxxxxxxxx>
Date: Tue, 19 Aug 2003 21:57:08 -0700 (PDT)
bread crumbs code
> Thanks, everyone. I took a little code and ideas
> from the posts and came
> up with this. It uses tail recursion, combined with
> some less verbose
> axis traversing. Armen's code didn't actually
> reverse the output when I
> ran it against my xml doc, it came out the same, but
> without the extra
> >>, but was more efficient.

Hi Joshua, yes you are right, I wrote the code fast,
and didn't properly look at the results... However,
with slight changes it works [by the way, I really
think that using axis is in the heart of XSLT ;)]. The
recursion can be replaced by xsl:for-each here.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param name="pageid" select="3"/>

	<xsl:template match="/">
		<xsl:variable name="selected-page"
select="//page[pageid = $pageid]"/>
		<xsl:variable name="selected-page-path"
select="$selected-page/ancestor-or-self::page"/>
		<docroot>
			<xsl:choose>
				<xsl:when test="$selected-page-path[not(pageid)]">
					[Broken chain]
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="output-the-path">
						<xsl:with-param name="node-set"
select="$selected-page-path"/>
					</xsl:call-template>
				</xsl:otherwise> 
			</xsl:choose>
		</docroot>	
	</xsl:template>
	
	<xsl:template name="output-the-path">
		<xsl:param name="node-set"/>
		<xsl:if test="$node-set">
			<xsl:variable name="current-item"
select="$node-set[1]"/>
			<a
href="index.cfm?pageid={$current-item/pageid}"><xsl:value-of
select="normalize-space($current-item/title)"/></a>
			<xsl:if test="(count($node-set) &gt; 1) and
($node-set[2]/pageid)">
				&gt;&gt;
				<xsl:call-template name="output-the-path">
					<xsl:with-param name="node-set"
select="$node-set[position() &gt; 1]"/>
				</xsl:call-template>					
			</xsl:if>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

The stylesheet also "recognizes" broken chains: if at
least on page has no "pageid" in the chain, then the
chain is invalid(i.e., to output the chain of links to
pages which have "pageid" and jump over pages without
"pageid" is not a good idea).

Regards,
Armen

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

 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.