xsl-list
[Top] [All Lists]

RE: Bread-crumbs nav from nested hierarchy in reverse order

2003-08-19 21:57:08
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



<Prev in Thread] Current Thread [Next in Thread>