[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Bread-crumbs nav from nested hierarchy in reverse order
Subject: Re: [xsl] Bread-crumbs nav from nested hierarchy in reverse order From: Armen Martirossian <armmarti@xxxxxxxxx> Date: Mon, 18 Aug 2003 23:55:36 -0700 (PDT) |
I can suggest to use ancestor-or-self axis here. Also I tried to simplify the code and make it more readable: <?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:call-template name="reverse"> <xsl:with-param name="node-set" select="$selected-page-path"/> </xsl:call-template> </docroot> </xsl:template> <xsl:template name="reverse"> <xsl:param name="node-set"/> <xsl:if test="$node-set"> <xsl:variable name="current-item" select="$node-set[last()]"/> <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[last() - 1]/pageid)"> >> <xsl:call-template name="reverse"> <xsl:with-param name="node-set" select="$node-set[position() < last()]"/> </xsl:call-template> </xsl:if> </xsl:if> </xsl:template> </xsl:stylesheet> The stylesheet doesn't output extra ">>" at the start of the path. Regards, Armen --- "Simerman, Joshua Michael" <jsimerma@xxxxxxxxxxx> wrote: > 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>>></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 > __________________________________ 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Bread-crumbs nav from nested , Simerman, Joshua Mic | Thread | RE: [xsl] Bread-crumbs nav from nes, Michael Kay |
Re: [xsl] Group and sort by group e, Mukul Gandhi | Date | RE: [xsl] advice on node-set fallba, Michael Kay |
Month |