Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2004, 08:40 AM
Registered User
 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Breadcrumb

Hi there,

Another breadcrumb problem. I tried to figure it out with one of the previous post, but I got stuck :(

Here's my XML file:

<Menus>
<Menu_id>1</Menu_id>
<Main_Menu_Nr>1</Main_Menu_Nr>
<Main_Menu_Name>Principles and Tricks</Main_Menu_Name>
<Parent_Menu_nr>0</Parent_Menu_nr>
<Page_id>215</Page_id>
</Menus>

<Menus>
<Menu_id>2</Menu_id>
<Main_Menu_Nr>2</Main_Menu_Nr>
<Main_Menu_Name>Changing Chords</Main_Menu_Name>
<Parent_Menu_nr>1</Parent_Menu_nr>
<Page_id>217</Page_id>
</Menus>

<Menus>
<Menu_id>3</Menu_id>
<Main_Menu_Nr>3</Main_Menu_Nr>
<Main_Menu_Name>Inversions</Main_Menu_Name>
<Parent_Menu_nr>1</Parent_Menu_nr>
<Page_id>628/Page_id>
</Menus>

<Menus>
<Menu_id>4</Menu_id>
<Main_Menu_Nr>4</Main_Menu_Nr>
<Main_Menu_Name>The Bass</Main_Menu_Name>
<Parent_Menu_nr>1</Parent_Menu_nr>
<Page_id>136</Page_id>
</Menus>

<Menus>
<Menu_id>5</Menu_id>
<Main_Menu_Nr>5</Main_Menu_Nr>
<Main_Menu_Name>The Melody</Main_Menu_Name>
<Parent_Menu_nr>1</Parent_Menu_nr>
<Page_id>560</Page_id>
</Menus>

<Menus>
<Menu_id>6</Menu_id>
<Main_Menu_Nr>6</Main_Menu_Nr>
<Main_Menu_Name>Inversion</Main_Menu_Name>
<Parent_Menu_nr>3</Parent_Menu_nr>
<Page_id>345</Page_id>
</Menus>

<Menus>
<Menu_id>7</Menu_id>
<Main_Menu_Nr>7</Main_Menu_Nr>
<Main_Menu_Name>Moving Up and Down</Main_Menu_Name>
<Parent_Menu_nr>3</Parent_Menu_nr>
<Page_id>359</Page_id>
</Menus>

etc.

Where <Parent_Menu_nr> is the parent, pointing to <Menu_id>

The names are to show up in a breadcrumb trail with a <a href= ..> link to the page <Page_id>.html added.

I am but a musician and no XSLT programmer and I reaaally tried.
Rgghh.

If anyone could point me in the right direction, I'd be very grateful.

Cheers,

Matt Brandt
email: [email protected]







 
Old October 5th, 2004, 02:41 PM
Registered User
 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again,

This is an addition to he previous post.
I came up with this, but didn't get any output
This is an edit of a previously posted xslt file.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0"
     xmlns:redirect="http://xml.apache.org/xalan/redirect"
     extension-element-prefixes="redirect">

    <xsl:param name="menu-id" select="1"/>

    <xsl:template match="Menus">
        <xsl:call-template name="output-bread-crumb">
            <xsl:with-param name="current" select="/Parent_menu_nr"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="output-bread-crumb">
        <xsl:param name="current"/>
        <xsl:choose>
            <xsl:when test="@current != 0">
                <xsl:call-template name="output-bread-crumb">
                    <xsl:with-param name="current" select="$current/@Parent_menu_nr"/>
                </xsl:call-template>
                &gt; <xsl:value-of select="$current/@Main_Menu_Name"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$current/@Main_Menu_Name"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

What am I doing wrong ?
Thanks in advance

Matt
email:[email protected]

P.s. by Breadcrumb I mean one of those long lines with parts of menus and submenus : Mainmenu -> Menu 1.1 -> Menu 1.1.2 etc.


 
Old October 7th, 2004, 04:43 AM
Registered User
 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And so I solved it myself :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
<!--
    A breadcrumb routine, where
    Main_Menu_Nr = number of a menu
    Main_Menu_Name = title of menu, to be put in breadcrumb
    Parent_Menu_nr = number of Parent, to be compared with Main_Menu_Nr
                   = 0 when there is no parent

    This routine calculates the breadcrumbs for ALL the Menu items.
    Output is a list of all the breadcrums
-->

    <xsl:variable name="newline">
    <xsl:text>
    </xsl:text>
    </xsl:variable>
    <xsl:variable name="breadc" select = "*" >
    </xsl:variable>

    <xsl:template match="dataroot">
        <xsl:for-each select ="Menus">
            <xsl:value-of select = "$newline"/>
            <xsl:value-of select = "Main_Menu_Nr"/>
            <xsl:call-template name="bc">
                        <xsl:with-param name="breadc" select="Main_Menu_Name" />
                        <xsl:with-param name="parentnr" select ="Parent_Menu_nr"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="bc">
          <xsl:param name="breadc" />
          <xsl:param name="parentnr"/>
          <xsl:choose>
                 <xsl:when test="$parentnr &gt; '0'">
                       <xsl:for-each select ="//Menus">
                         <xsl:if test ="Main_Menu_Nr = $parentnr" >
                               <xsl:call-template name="bc">
                             <xsl:with-param name="breadc" select= "concat (Main_Menu_Name,'---',$breadc)"/>
                            <xsl:with-param name="parentnr" select = "Parent_Menu_nr"/>
                            </xsl:call-template>
                    </xsl:if>
                </xsl:for-each>
          </xsl:when>
          <xsl:when test="$parentnr = '0'">
                   <xsl:value-of select= "concat(' ',$breadc)" />
                 </xsl:when>
             </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Cheers,

Matt 'xslmatty' Brandt






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to have a breadcrumb track pure history? jazzcatone ASP.NET 2.0 Basics 0 February 5th, 2007 03:34 PM
how to add breadcrumb navigation to a LAMP site avail1now PHP How-To 0 February 17th, 2006 05:03 PM
XML/XSL BreadCrumb Trail fortgjort XSLT 8 August 28th, 2003 04:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.