Subject: RE: [xsl] Bread-crumbs nav from nested hierarchy in reverse order From: "Michael Kay" <mhk@xxxxxxxxx> Date: Tue, 19 Aug 2003 08:47:12 +0100 |
The simple answer is recursion: instead of doing apply-templates on the children of a node, do apply-templates on its parent (but in a special mode, to avoid infinite loops). Alternatively, <xsl:sort select="position()" data-type="number" order="descending"/> will process a node-set in reverse document order. Michael Kay > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Simerman, Joshua Michael > Sent: 19 August 2003 04:52 > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Bread-crumbs nav from nested hierarchy in reverse order > > > 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 > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Bread-crumbs nav from nes, Armen Martirossian | Thread | RE: [xsl] Bread-crumbs nav from nes, Simerman, Joshua Mic |
RE: [xsl] Group and sort by group e, Michael Kay | Date | RE: [xsl] advice on node-set fallba, Julian Reschke |
Month |