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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:43:42+00:00 2026-06-11T20:43:42+00:00

I am using the web.sitemap which is created using VS.net 2010 along with a

  • 0

I am using the web.sitemap which is created using VS.net 2010 along with a XSLT to create a clean CSS-able menu.
I have modified the xslt from Cyotec to strip out the first node however I am so far unable to work out how to search within to display only the links depending on the role of the user.

The XSLT is as below:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:map="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" exclude-result-prefixes="map">
  <xsl:output method="xml" encoding="utf-8" indent="yes"/>

  <xsl:template name="mapNode" match="/">
    <ul id="main-menu">
      <xsl:apply-templates select="*"/>
    </ul>
  </xsl:template>

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

  <xsl:template match="map:siteMapNode">
    <xsl:if test="/siteMap/SiteMapNode[@roles != 'Admin']">
            <li>
          <a href="{substring(@url, 2)}" title="{@description}">
            <xsl:value-of select="@title"/>
          </a>

          <xsl:if test="map:siteMapNode">
            <xsl:call-template name="mapNode"/>
          </xsl:if>

        </li>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

The XML looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/" title=""  description="Anon" roles="*">
    <siteMapNode url="~/anon.aspx" title="Anon"  description="Anon" roles="*" />
    <siteMapNode url="~/admin1.aspx" title="Admin1"  description="Admin Only" roles="Admin"/>
    <siteMapNode url="~/admin2.aspx" title="Admin2"  description="Admin Only" roles="Admin">
      <siteMapNode url="~/admin3.aspx" title="Admin3"  description="Admin Only" roles="Admin"/>
    </siteMapNode>
  </siteMapNode>
</siteMap>

I am wanting to only output the urls titles and descriptions where roles != Admin
Everything works fine without the search.
Is anyone able to shed some light on the ‘if’ function, or suggest a better way of achieving this?
Thanks in advance

  • 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-11T20:43:43+00:00Added an answer on June 11, 2026 at 8:43 pm

    The problem with your current xsl:if condition….

    <xsl:if test="/siteMap/SiteMapNode[@roles != 'Admin']"> 
    

    …. is that the first forward slash means it is an absolute path, starting from the root element, so all the xsl:if is saying is whether there is any SiteMapNode, immediately under the siteMap element, that is not an Admin role. This means it will always be true in your case.

    You really only want to check the role of the current element

    <xsl:if test="@roles != 'Admin'"> 
    

    However, there is a tidier way of doing this. Remove the xsl:if condition, and just have a separate template to match the admin role elements, and ignore them.

    <xsl:template match="map:siteMapNode[@roles='Admin']"/>
    

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:map="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" exclude-result-prefixes="map">
       <xsl:output method="xml" encoding="utf-8" indent="yes"/>
    
       <xsl:template name="mapNode" match="/">
          <ul id="main-menu">
             <xsl:apply-templates select="*"/>
          </ul>
       </xsl:template>
    
       <xsl:template match="/*/*">     
          <xsl:apply-templates select="*"/>     
       </xsl:template>     
    
       <xsl:template match="map:siteMapNode[@roles='Admin']"/>
    
       <xsl:template match="map:siteMapNode">
          <li>
             <a href="{substring(@url, 2)}" title="{@description}">
                <xsl:value-of select="@title"/>
             </a>
             <xsl:if test="map:siteMapNode">
                <xsl:call-template name="mapNode"/>
             </xsl:if>
          </li>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <ul id="main-menu">
       <li>
          <a href="/anon.aspx" title="Anon">Anon</a>
       </li>
    </ul>
    

    Do note the template that matches the admin role element is more specific that the template that matches any SiteMapNode element and so the XSLT processor will give priority to this when matching.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using standard ASP.NET and a Web.sitemap file which describes the navigation structure of
Using a asp:SiteMapPath control along with Web.sitemap, I'm able to get a bread crumb
I want to create tree structure using web service. I have used bottom up
I'm rewriting a web application to ASP.Net 4.0 and have included a Menu control
In ASP.Net I usually drive my primary navigation using a standard web.sitemap file such
We are using a custom sitemap provider to populate an ASP.Net application's menu control
We have several ASP.NET applications that use a sitemap which is populated via a
Using web forms I know that you can only have one ASP.NET form on
I am new to using web services. I am assigned a task in which
Here is what I have in my web.config: <customErrors mode=On defaultRedirect=/pages/sitemap> <error statusCode=404 redirect=/pages/sitemap

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.