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 5991751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:25:57+00:00 2026-05-22T23:25:57+00:00

I am trying to write a breadcrumb navigation by using XSL to transform XML.

  • 0

I am trying to write a breadcrumb navigation by using XSL to transform XML.

Here is a piece of the XML file I am using:

<Menu>
<ID>22486a60-2bfe-46ba-96ee-7ea92b6ca5bb</ID>
<PageID>00000000-0000-0000-0000-000000000000</PageID>
<Link/>
<Target/>
<Title>Main Menu</Title>
<Image/>
<Items>
    <Menu>
        <ID>44595707-a331-49ae-a8ed-4bc1cef22e4f</ID>
        <PageID>83a1df5f-2909-4c8a-9aa7-a4f2e0111d7c</PageID>
        <Link>/home.aspx</Link>
        <Target>_self</Target>
        <Title>Home</Title>
        <Image/>
        <Items/>
    </Menu>
    <Menu>
        <ID>a9fd822b-838f-4129-9628-4ce667005450</ID>
        <PageID>88e8e3c3-39e3-40a4-9dfd-476f2082f4e0</PageID>
        <Link>/About-Us.aspx</Link>
        <Target>_self</Target>
        <Title>About Us</Title>
        <Image/>
        <Items/>
    </Menu>
    <Menu>
        <ID>3aa256eb-9f80-42b3-b637-2e22f7008adb</ID>
        <PageID>3369b394-1aec-4a9f-bb9f-1bae7bdde858</PageID>
        <Link>/Products.aspx</Link>
        <Target>_self</Target>
        <Title>Products</Title>
        <Image/>
        <Items>

            <Menu>
                <ID>b2f7efae-19d7-4177-9874-962944af9836</ID>
                <PageID>88e8e3c3-39e3-40a4-9dfd-476f2082f4e0</PageID>
                <Link>/Aprons.aspx</Link>
                <Target>_self</Target>
                <Title>Aprons</Title>
                <Image/>
                <Items/>
            </Menu>

I am having trouble getting the XSL to display the current page. It displays all the ancestors but not the current page. Here is what I’ve come up with so far:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
    <xsl:output method="html" omit-xml-declaration="yes"/>
    <xsl:param name="CurrentPage">a5e2418a-f42e-4c0d-9d63-515ecb6af79e</xsl:param>

    <xsl:template match="/">
        <ul id="breadcrumb">
            <xsl:call-template name="innerNode">
                <!--<xsl:value-of select="ancestor-or-self::PageID = $CurrentPage"/>-->
            </xsl:call-template>
        </ul>
    </xsl:template>

    <xsl:template name="innerNode">
        <xsl:for-each select="Menu/Items">
            <xsl:if test="descendant::*/PageID = $CurrentPage">
                <li>
                    <xsl:choose>
                        <xsl:when test="not(PageID = $CurrentPage)">
                            <a href="/"><xsl:value-of select="../Title"/></a>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="Items"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </li>
            </xsl:if>
            <xsl:call-template name="innerNode"/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Any help would be appreciated!

Thanks,
Jason

  • 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-05-22T23:25:58+00:00Added an answer on May 22, 2026 at 11:25 pm

    The following stylesheet first selects the menu item with the correct page ID, then displays all its ancestors, and finally displays the menu item itself. This approach is more effective than repeatedly calculating the expression descendant::*.

    Note that if the page ID does not exist in the menu structure, no ul element is output. If you want to display the ul element even if it will be empty, change the stylesheet so that ul wraps xsl:for-each.

    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" omit-xml-declaration="yes"/>
        <xsl:param name="CurrentPage">a5e2418a-f42e-4c0d-9d63-515ecb6af79e</xsl:param>
    
        <xsl:template match="/">
            <xsl:for-each select="//Menu[PageID = $CurrentPage]">
                <ul id="breadcrumb">
                    <xsl:for-each select="ancestor::Menu">
                        <li><a href="{Link}"><xsl:value-of select="Title"/></a></li>
                    </xsl:for-each>
                    <li><xsl:value-of select="Title"/></li>
                </ul>
            </xsl:for-each>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to write an object i made onto a file using Object output
I'm trying to write some PHP to upload a file to a folder on
Trying to write a couple of functions that will encrypt or decrypt a file
i trying to write a comment in each PHP file, then the comment will
i'm trying to write simple C openssl client and server. Here is client's code:
I'm trying write a query to find records which don't have a matching record
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a blog post which includes a code segment inside a
I'm trying to write a custom WPF ValidationRule to enforce that a certain property

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.