|
[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
> 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> 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. <?xml version="1.0" encoding="utf-8"?> <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" omit-xml-declaration="yes"/> <xsl:param name="pageid" select="23"/> <xsl:template match="/"> <div id="breadbar"> <ul> <xsl:apply-templates select="//page[pageid = $pageid]"/> </ul> </div> </xsl:template> <xsl:template match="node()"> <xsl:if test="pageid"> <xsl:apply-templates select=".."/> <xsl:call-template name="bread-crumb"/> </xsl:if> </xsl:template> <xsl:template name="bread-crumb"> <li> <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:text> >> </xsl:text> </li> </xsl:template> </xsl:stylesheet> 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
|
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
|

Cart








