[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
> 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) > 1) and ($node-set[2]/pageid)"> >> <xsl:call-template name="output-the-path"> <xsl:with-param name="node-set" select="$node-set[position() > 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|