Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:55:10+00:00 2026-06-11T07:55:10+00:00

I have an XML like: <menu> <node id=home url=url1.php> <label>Homepage</label> <node id=user url=url2.php><label>User profile</label></node>

  • 0

I have an XML like:

<menu>
    <node id="home" url="url1.php">
          <label>Homepage</label>
          <node id="user" url="url2.php"><label>User profile</label></node>
          <node id="help" url="url3.php"><label>Help page</label></node>
     ...
    </node>
</menu>

Its used to generate a menu, the XML has node tags nested at any level under the first “home” node.
I pass a parameter called $id with PHP which gives the current active menu item.

(The <label> is in a separate tag and not as attribute because I’ve many labels for localization, actual xml is like <label lang='en'>...</label><label lang='it'>...</label>)

The idea is to use various XSLs to generate main menu, breadcrumbs, section titles (top menu).
For the main menu I’ve managed to do this:

<xsl:template match="menu">
     <xsl:apply-templates select="node" />
</xsl:template>

<xsl:template match="//node">
    <ul>
        <li>
            <a>
               <xsl:if test="@id=$id">
                  <xsl:attribute name='class'>active</xsl:attribute>
               </xsl:if>
               <xsl:attribute name='href'>
                  <xsl:value-of select="@url" />
               </xsl:attribute>
               <xsl:value-of select="label"/>
            </a>
            <xsl:if test="count(child::*)>0">
               <xsl:apply-templates select="node" />
            </xsl:if>
        </li>
    </ul>
    </xsl:template>
</xsl:stylesheet>

And it works. But I’m stuck with the breadcrumbs.
How can I isolate only a specific node with @id=$id and his ancestors, to build breadcrumbs up to current page from home?

Resulting html should be, for a node ad the third nested level:

<ul>
    <li><a href="url1.php">Home</a></li>
    <li><a href="urla.php">Some child of home</a></li>
    <li><a href="urlb.php">Some grandchild of home</a></li>
    <li><a class='active' href="urlc.php">Current page which is child of the above</a></li>
</url>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:55:12+00:00Added an answer on June 11, 2026 at 7:55 am

    The breadcrumb you can do like this, by selecting the active node and then walking the ancestors, like so:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" version="1.0" indent="yes"/>
    
        <xsl:template match="/">
            <!--Obviously set your PHP variable here-->
            <xsl:variable name="id">bananas</xsl:variable>
            <!--Find this node somewhere in the tree-->
            <xsl:apply-templates select=".//node[@id=$id]"/>
        </xsl:template>
    
        <xsl:template match="node">
            <!--Walk the ancestors-->
            <xsl:for-each select="ancestor-or-self::node">
            <!--Snappy path separator here-->
                <xsl:text> --> </xsl:text>
                <a>
                    <xsl:attribute name="href">
                        <xsl:value-of select="@url" />
                    </xsl:attribute>
                    <xsl:value-of select="label/text()"/>
                </a>
            </xsl:for-each>
        </xsl:template>
    
    </xsl:stylesheet>    
    

    Sample Menu Xml:

    <menu>
        <node id="home" url="url1.php">
              <label>Homepage</label>
              <node id="user" url="url2.php"><label>User profile</label></node>
              <node id="help" url="url3.php"><label>Help page</label></node>
        </node>
        <node id="products" url="urlN1.php">
            <label>Products</label>
            <node id="food" url="urlN2.php">
                <label>Food</label>
                <node id="fruit" url="urlN3.php">
                    <label>Fruit</label>
                    <node id="bananas" url="urlN4.php">
                        <label>Bananas</label>
                    </node>
                </node>
                <node id="clothes" url="urlN3.php">
                    <label>Clothes</label>
                    <node id="shirts" url="urlN4.php">
                        <label>Shirts</label>
                    </node>
                </node>
            </node>
        </node>
    </menu>
    

    Edit Update – You’ve updated the Q to display the breadcrumb as a list – here’s an updated template just in case 🙂

    <xsl:template match="node">
        <ul>
            <!--Walk the ancestors-->
            <xsl:for-each select="ancestor-or-self::node">
                <li>
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="@url" />
                        </xsl:attribute>
                        <xsl:value-of select="label/text()"/>
                    </a>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an options_menu.xml file like this: <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android> <item android:id=@+id/search
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have a collapsible menu item that is defined in XML like this: <item
Say I have an .xml file with a menu that looks like this. <?xml
have an xml file like this. <?xml version =1.0 encoding =utf-8?> <menu> <menuNode title=Register
I have an XML Sitemap like this <?xml version=1.0 encoding=utf-8 ?> <Menu> <MenuItem Name=Page
I have an xml document that goes like this: <Menu> <Category name=Comida Rapida> <Food
I have xml like this: <rule> <word>I</word> <word>need</word> <word>more</word> <marker> <word>money</word> </marker> <word>now</word> </rule>
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I have XML like, <items> <item> <products> <product>laptop</product> <product>charger</product> <product>Cam</product> </products> </item> <item> <products>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.