locked
xslt: move all nodes up a level RRS feed

  • Question

  • User846546683 posted

    My xslt script reads the web.sitemap and outputs it to a nested UL.  

    I am pasting my xslt script, followed by my web.sitemap.

    What I would like to do is move all nodes up a level so that the starting node and first level node are in the same level.

    In other words: 

    Intended html UL output (in conceptual form)
    
    * Top level node (homepage)
    * First level elements
        *  Second level elements
             * Third level elements

    Is there a way to do this?  Thank you

    XSLT Script:

    <?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"  version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="yes" />
        <xsl:strip-space elements="*"/>   
        
        <xsl:template  match="map:siteMapNode">
            <li>
                <a href="http://fnssnvtestsite.com{substring(@url, 2)}">
                    <xsl:value-of select="@title"/>
                </a>
                <xsl:if test="map:siteMapNode">
                    <xsl:call-template name="mapNode"/>
                </xsl:if>
            </li>
        </xsl:template>
    
        <xsl:template name="mapNode" match="map:siteMap">
            <xsl:choose>
                <xsl:when test="@*">
                    <ul>
                        <xsl:apply-templates />
                    </ul>
                </xsl:when>
                <xsl:otherwise>
                    <ul id="menuUL" class="sm sm-blue">
                        <xsl:apply-templates />
                    </ul>                
                </xsl:otherwise>                
            </xsl:choose>
            
        </xsl:template>
    
    </xsl:stylesheet>

     Web.sitemap:

    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
        <siteMapNode url="~/index.aspx" title="Homepage"  description="Homepage">
            <siteMapNode url="~/Vehicles/vehicles.aspx" title="Vehicles"  description="Main vehicles page">
                <siteMapNode url="~/Vehicles/New_Vehicles.aspx" title="New Vehicles"></siteMapNode>
                <siteMapNode url="~/Vehicles/Used_Vehicles.aspx" title="Used Vehicles">
                    <siteMapNode url="~/Vehicles/Side_Entry_Vehicles.aspx" title="Side Entry" />
                    <siteMapNode url="~/Vehicles/Rear_Entry_Vehicles.aspx" title="Rear Entry" />                
                </siteMapNode>
                <siteMapNode url="~/Vehicles/mv_1.aspx" title="MV-1">
                    <siteMapNode url="~/Vehicles/mv_1/se_standard_edition.aspx" title="SE Standard Edition"></siteMapNode>
                </siteMapNode>
                <siteMapNode url="~/Vehicles/Rentals_Accessible_Van.aspx" title="Accessible Van Rentals" />
                <siteMapNode url="~/Vehicles/Commercial_Vans.aspx" title="Commercial Vans">
                    <siteMapNode url="~/Vehicles/Norcal_Ford_Transit_Connect.aspx" title="Norcal Ford Transit Connect"></siteMapNode>
                    <siteMapNode url="~/Vehicles/Nissan_NV.aspx" title="Nissan NV"></siteMapNode>
                </siteMapNode>
                
                <siteMapNode url="~/Vehicles/Specialty_Vehicles.aspx" title="Specialty" />
                <siteMapNode url="~/Vehicles/Truck_Conversions.aspx" title="Truck Conversions"   />
                <siteMapNode url="~/Vehicles/Vans_For_Quadriplegic_Driver.aspx" title="Vans for Quadriplegic Drivers"   />
            </siteMapNode>
            <siteMapNode url="~/Products/products.aspx" title="Products">
                <siteMapNode url="~/Products/Airbag_Safety/Airbag_Safety.aspx" title="Airbag Safety">
                    <siteMapNode url="~/Products/Airbag_Safety/AirBag_Danger_More_Info.aspx" title="Airbag Danger: More Information"  ></siteMapNode>
                    <siteMapNode url="~/Products/Airbag_Safety/AirBag_Safety_On_Off_Switch.aspx" title="On/Off Switch"  ></siteMapNode>
                    <siteMapNode url="~/Products/Airbag_Safety/DrEvans_Excerpts_from_Traffic_Safety.aspx" title="Excerpts from &quot;Traffic Safety&quot;" ></siteMapNode>
                    <siteMapNode url="~/Products/Airbag_Safety/DrSmock_Protecting_Yourself_From_Airbag_Injuries.aspx" title="Protecting yourself from Air Bag Injuries"></siteMapNode>
                </siteMapNode>
                <siteMapNode url="~/Products/Incline_Platform_Lifts.aspx" title="Incline Platform Lifts">
                    <siteMapNode url="~/Products/Incline_Platform_Lifts/Harmar_IL500_Sierra_Incline_Platform_Lift.aspx" title="Harmar IL500 (Sierra Incline Platform Lift)"></siteMapNode>
                </siteMapNode>
                <siteMapNode url="~/Products/Ramps.aspx" title="Ramps">
                    <siteMapNode url="~/Products/Ramps/Harmar_AR_100_Single_Fold_Ramp.aspx" title="Harmar AR100 (Single Fold Ramp)"></siteMapNode>
                    <siteMapNode url="~/Products/Ramps/Harmar_AR_200_Rubber_Threshold_Ramp.aspx" title="Harmar AR200 (Rubber Threshold Ramp)"></siteMapNode>
                    <siteMapNode url="~/Products/Ramps/Harmar_AR_300_Multi_Fold_Ramp.aspx" title="Harmar AR300 (Multi-Fold Ramp)"></siteMapNode>
                    <siteMapNode url="~/Products/Ramps/Harmar_AR_500_Adjustable_Threshold_Ramp.aspx" title="Harmar AR500 (Adjustable Threshold Ramp)"></siteMapNode>
                    <siteMapNode url="~/Products/Ramps/Harmar_AR_800_Threshold_Ramp.aspx" title="Harmar AR800 (Threshold Ramp)"></siteMapNode>
                </siteMapNode>
                <siteMapNode url="~/Products/StairLifts.aspx" title="Stairlifts">
                    <siteMapNode url="~/Products/Stairlifts/Acorn_120_Outdoor_Stairlift.aspx" title="Acorn 120 Outdoor"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Acorn_120_Stairlift.aspx" title="Acorn 120"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Acorn_180_Stairlift.aspx" title="Acorn 180"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Harmar_CSL500_Helix_Curved_Stairlift.aspx" title="Harmar CSL500 Helix Curved"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Harmar_SL400_Vantage_Straight_Stair_Lift.aspx" title="Harmar SL400 Vantage Straight"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Harmar_SL600_Pinnacle_Premium.aspx" title="Harmar SL600 Pinnacle Premium"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Harmar_SL600HD_Pinnacle_Heavy_Duty_Stair_Lift.aspx" title="Harmar SL600HD Pinnacle Heavy Duty"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Harmar_SL3500OD_Outdoor.aspx" title="Harmar SL3500OD Outdoor"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Harmar_RP350_Alpine_II_Standard.aspx" title="Harmar RP350 Alpine II Standard"></siteMapNode>
                    <siteMapNode url="~/Products/Stairlifts/Harmar_RP350S_Alpine_II_Signature_Stair_Lift.aspx" title="Harmar RP350S Apine II Signature"></siteMapNode>
                </siteMapNode>
                <siteMapNode url="~/Products/Vehicle_Adaptations/Systems_Controls/Systems_Controls.aspx" title="Systems Controls">
                    <siteMapNode title="Automotive Secondary Systems Controls">
                        <siteMapNode title="Logitouch" url="~/Products/Vehicle_Adaptations/Systems_Controls/Logitouch_Secondary_Systems_Control.aspx"></siteMapNode>
                        <siteMapNode title="DSI CP05 Palm Control" url="~/Products/Vehicle_Adaptations/Systems_Controls/DSI_CP05_Palm_Control.aspx"></siteMapNode>
                        <siteMapNode title="Crescent Industries: Automotive Secondary Control Systems" url="~/Products/Vehicle_Adaptations/Systems_Controls/Crescent_Industries_Secondary_Systems_Controls.aspx"></siteMapNode>
                    </siteMapNode>
                    <siteMapNode title="Electronic Parking Brakes">
                    </siteMapNode>
                    <siteMapNode title="Floor System"></siteMapNode>
                </siteMapNode>
                <siteMapNode url="~/Products/Vehicle_Adaptations/Vehicle_Adaptations.aspx" title="Vehicle Adaptations">
                    <siteMapNode url="~/Products/Vehicle_Adaptations/Steering_Controls/Steering_Controls.aspx" title="Steering Controls">
                        <siteMapNode url="~/Products/Vehicle_Adaptations/Steering_Controls/Drive_Master_Modified_Steering_Systems.aspx" title="Drive-Master Modified Steering Systems"></siteMapNode>
                        <siteMapNode url="~/Products/Vehicle_Adaptations/Steering_Controls/Drive_Master_Pedal_Extensions.aspx" title="Drive-Master Pedal Extensions"></siteMapNode>
                    </siteMapNode>
                </siteMapNode>
                <siteMapNode url="~/Products/Vertical_Platform_Lifts.aspx" title="Vertical Platform Lifts">
                    <siteMapNode url="~/Products/Vertical_Platform_Lifts/Harmar_CPL_Vertical_Platform_Lift.aspx" title="Harmar CPL (Commercial Vertical Platform Lift)"></siteMapNode>
                    <siteMapNode url="~/Products/Vertical_Platform_Lifts/Harmar_CPL_400H_1400H_Hydraulic_CPL_with_Modular_Tower.aspx" title="Harmar CPL (400H-1400H Hydraulic CPL with Modular Tower)"></siteMapNode>
                    <siteMapNode url="~/Products/Vertical_Platform_Lifts/Harmar_CPL_400P_Portable_Vertical_Platform_Lift.aspx" title="Harmar CPL (400P Portable Vertical Platform Lift)"></siteMapNode>
                    <siteMapNode url="~/Products/Vertical_Platform_Lifts/Harmar_EPL_Enclosed_Vertical_Platform_Lift.aspx" title="Harmar EPL (Enclosed Vertical Platform Lift)"></siteMapNode>
                    <siteMapNode url="~/Products/Vertical_Platform_Lifts/Harmar_RPL_Residential_Vertical_Platform_Lift.aspx" title="Harmar RPL (Residential Vertical Platform Lift)"></siteMapNode>
                    <siteMapNode url="~/Products/Vertical_Platform_Lifts/Harmar_TG400_Toe_Guard_Commercial_Platform_Lift.aspx" title="Harmar TG400 (Toe Guard Commercial Platform Lift)"></siteMapNode>
                </siteMapNode>
            </siteMapNode>
            <siteMapNode url="~/About_Us/about_us.aspx" title="About Us">
                <siteMapNode url="~/About_Us/find_us.aspx" title="Find Us" />
                <siteMapNode url="~/About_Us/latest_news.aspx" title="Latest News" />
                <siteMapNode url="~/About_Us/Special_Needs_Lifestyles.aspx" title="Radio Show" />
            </siteMapNode>
            <siteMapNode url="~/resources.aspx" title="Resources">
                <siteMapNode url="~/ADA_Guidelines.aspx" title="ADA Requirements"></siteMapNode>
                <siteMapNode url="~/Brochures.aspx" title="Brochures">
                    <siteMapNode title="Incline Platform Lifts">
                        <siteMapNode title="Harmar IL500 Sierra Incline Platform Lift (897 KB)" url="~/References/Brochures/Harmar_Sierra_Incline_Platform_Lift.pdf"></siteMapNode>
                    </siteMapNode>
                    <siteMapNode title="Ramps">
                        <siteMapNode title="Harmar Ramps (2.13 MB)" url="~/References/Brochures/Harmar_Ramps.pdf"></siteMapNode>
                    </siteMapNode>
                    <siteMapNode title="Stairlifts">
                        <siteMapNode title="Acorn">
                            <siteMapNode title="Acorn 120 Outdoor Stairlift (1.32 MB)" url="~/PDFs/Stairlifts/Acorn_120_Outdoor_Stairlift.pdf"></siteMapNode>
                            <siteMapNode title="Acorn 120 Stairlift (1.85 MB)" url="~/PDFs/Stairlifts/Acorn_120_Stairlift.pdf"></siteMapNode>
                            <siteMapNode title="Acorn 120 Stairlift Presentation (3.10 MB)" url="~/PDFs/Stairlifts/Acorn_120_Stairlift_Information.pdf"></siteMapNode>
                            <siteMapNode title="Acorn 180 Stairlift (2.35 MB)" url="~/PDFs/Stairlifts/Acorn_180_Stairlift.pdf"></siteMapNode>
                            <siteMapNode title="Acorn 180 Stairlift Presentation (2.52 MB)" url="~/PDFs/Stairlifts/Acorn_180_Stairlift_Information.pdf"></siteMapNode>
                        </siteMapNode>
                        <siteMapNode title="Harmar">
                            <siteMapNode title="Harmar Stairlifts (2.74 MB)" url="~/PDFs/Stairlifts/Harmar_Stair_Lifts_Brochure.pdf"></siteMapNode>
                            <siteMapNode title="Harmar Vertical Platform Lifts (1.17 MB)" url="~/References/Brochures/Harmar_Vertical_Platform_Lifts.pdf"></siteMapNode>
                        </siteMapNode>
                    </siteMapNode>
                </siteMapNode>
                <siteMapNode title="Brochure Request"></siteMapNode>            
                <siteMapNode url="~/Rebates.aspx" title="Rebates"></siteMapNode>
                <siteMapNode url="~/References.aspx" title="References">
                    <siteMapNode title="Manuals">
                        <siteMapNode title="Incline Platform Lifts">
                            <siteMapNode title="Harmar IL500 Sierra Incline Platform Lift (786 KB)" url="~/References/Manuals/Harmar_Sierra_Incline_Platform_Lift.pdf"></siteMapNode>
                        </siteMapNode>
                        <siteMapNode title="Ramps">
                            <siteMapNode title="Harmar Portable Ramps (450 KB)" url="~/References/Manuals/Harmar_Portable_Ramps.pdf"></siteMapNode>
                        </siteMapNode>
                        <siteMapNode title="Stairlifts">
                            <siteMapNode title="Harmar Helix Curved Stairlift (2.93 MB)" url="~/References/Manuals/Harmar_Helix_Curved_Stairlift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar SL400 (1.80 MB)" url="~/References/Manuals/Harmar_SL400.pdf"></siteMapNode>
                            <siteMapNode title="Harmar SL600 (3.01 MB)" url="~/References/Manuals/Harmar_Pinnacle.pdf"></siteMapNode>
                            <siteMapNode title="Harmar SL600HD (1.42 MB)" url="~/References/Manuals/Harmar_Pinnacle_Heavy_Duty_Stair_Lift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar RP350 Alpine (2.29 MB)" url="~/References/Manuals/Harmar_Alpine.pdf"></siteMapNode>
                        </siteMapNode>
                        <siteMapNode title="Vertical Platform Lifts">
                            <siteMapNode title="Harmar CPL (Commercial Vertical Platform Lift) (3.51 MB)" url="~/References/Manuals/Harmar_CPL_Vertical_Platform_Lift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar RPL (Residential Platform Lift) (1.09 MB)" url="~/References/Manuals/Harmar_RPL.pdf"></siteMapNode>
                        </siteMapNode>
                    </siteMapNode>
                    <siteMapNode title="Sell Sheets">
                        <siteMapNode title="Incline Platform Lifts">
                            <siteMapNode title="Harmar IL500 Sierra Incline Platform Lift (1.01 MB)" url="~/References/Sell_Sheets/Harmar_Sierra_IL500_Incline_Platform_Lift.pdf"></siteMapNode>
                        </siteMapNode>
                        <siteMapNode title="Stiarlifts">
                            <siteMapNode title="Harmar CSL500 Helix Curved (905 KB)" url="~/References/Sell_Sheets/Harmar_CSL500_Helix_Curved.pdf"></siteMapNode>
                            <siteMapNode title="Harmar SL400 Stair Lift (2.45 KB)" url="~/References/Sell_Sheets/Harmar_SL400_Stair_Lift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar SL600 Stair Lift (1.12 MB)" url="~/References/Sell_Sheets/Harmar_SL600_Premium_Stair_Lift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar SL600HD Stair Lift (514.KB)" url="~/References/Sell_Sheets/Harmar_SL600HD_Heavy_Duty_Stair_Lift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar SL350OD Outdoor Stair Lift (1.31 MB)" url="~/References/Sell_Sheets/Harmar_SL350OD.pdf"></siteMapNode>
                            <siteMapNode title="Harmar RP350 Alpine (1.00 MB)" url="~/References/Sell_Sheets/Harmar_RP350_and_RP350S_Stair_Lifts.pdf"></siteMapNode>
                        </siteMapNode>
                        <siteMapNode title="Vertical Platform Lifts">
                            <siteMapNode title="Harmar CPL (Commercial Vertical Platform Lift) (617 KB)" url="~/References/Sell_Sheets/Harmar_CPL_Vertical_Platform_Lift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar CPL (400H-1400H Hydraulic CPL with Modular Tower) (1.07 MB)" url="~/References/Sell_Sheets/Harmar_CPL_400H_1400H_Hydraulic_VPL_with_Modular_Tower.pdf"></siteMapNode>
                            <siteMapNode title="Harmar EPL (Enclosed Vertical Platform Lift) (639 KB)" url="~/References/Sell_Sheets/Harmar_EPL_Vertical_Platform_Lift.pdf"></siteMapNode>
                            <siteMapNode title="Harmar RPL (Residential Platform Lift) (2.21 MB)" url="~/References/Sell_Sheets/Harmar_RPL.pdf"></siteMapNode>
                            <siteMapNode title="Harmar TG400 (Toe Guard Commercial Platform Lift) (576 KB)" url="~/References/Sell_Sheets/Harmar_TG400.pdf"></siteMapNode>
                        </siteMapNode>
                    </siteMapNode>
                </siteMapNode>            
            </siteMapNode>
            <siteMapNode url="~/Sitemap.aspx" title ="Sitemap" />
        </siteMapNode>
    </siteMap>
    

    Sunday, April 26, 2015 6:18 PM

Answers

  • User-271186128 posted

    Hi HatesSunlight,

    From my point of view, I suggest you could try to remove the Home page node from the web.sitemap, then add the HomePage menu in web page separately. Here is a sample, please refer to it.

    Code in web.sitemap:

    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
        <siteMapNode url="~/Vehicles/vehicles.aspx" title="Vehicles" testlevel="1"  description="Main vehicles page">
          <siteMapNode url="~/Vehicles/New_Vehicles.aspx" title="New Vehicles"></siteMapNode>
          <siteMapNode url="~/Vehicles/Used_Vehicles.aspx" title="Used Vehicles">
            <siteMapNode url="~/Vehicles/Side_Entry_Vehicles.aspx" title="Side Entry" />
            <siteMapNode url="~/Vehicles/Rear_Entry_Vehicles.aspx" title="Rear Entry" />
          </siteMapNode>
         ...
    </siteMap>
    

    Code in page (.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" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
    
      <xsl:template name="mapNode" match="/map:siteMapNode">
        <ul>
          <xsl:apply-templates select="map:siteMapNode"/>
        </ul>
      </xsl:template>
    
      <xsl:template match="map:siteMapNode">
    
        <li>
          <a href="{@url}">
            <xsl:value-of select="@title"/>
          </a>
          <xsl:if test="map:siteMapNode" >
            <xsl:call-template name="mapNode"/>
          </xsl:if>
        </li>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Code in page (.aspx)

          <div id="content">
                <ul>
                    <li>
                        <a href="#">Home Page</a>
                    </li>
                <%= MenuList %>
                </ul>
            </div>
    
            public string MenuList = string.Empty;
            protected void Page_Load(object sender, EventArgs e)
            {
                DataSet ds = new DataSet();
                ds.ReadXml(Server.MapPath("~/Web.sitemap"));
    
                string strXML = ds.GetXml();
                MenuList = GetHtml(Server.MapPath("MenuTest.xslt"), strXML);
            }
    
            public static string GetHtml(string xsltPath, string xml)
            {
                MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(xml));
                XPathDocument document = new XPathDocument(stream);
                StringWriter writer = new StringWriter();
                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load(xsltPath);
                transform.Transform(document, null, writer);
                return writer.ToString();
            }

    The screenshot:

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2015 6:11 AM
  • User846546683 posted

    Thanks again. Your solution really did help me out.

    There's just one tweak I had to apply to make sure that the root node wasn't included (bolded in the script quote).  In this case, I required that the specific sitemap node with the title attribute of "Homepage" not be included. It would be nice if there was a more generic way to do this, but at least it did the job in this specific case.

        <xsl:template match="map:siteMapNode[@title!='Homepage']">
    <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" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
    
        <xsl:template name="mapNode" match="/map:siteMapNode">
            <ul>
                <xsl:apply-templates select="map:siteMapNode"/>
            </ul>
        </xsl:template>
    
        <xsl:template match="map:siteMapNode[@title!='Homepage']">
            <li>
                <a href="http://fnssnvtestsite.com{substring(@url, 2)}">
                    <xsl:value-of select="@title"/>
                </a>
                <xsl:if test="map:siteMapNode">
                    <xsl:call-template name="mapNode"/>
                </xsl:if>
            </li>
        </xsl:template>
    </xsl:stylesheet>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2015 2:09 AM

All replies

  • User-271186128 posted

    Hi HatesSunlight,

    From my point of view, I suggest you could try to remove the Home page node from the web.sitemap, then add the HomePage menu in web page separately. Here is a sample, please refer to it.

    Code in web.sitemap:

    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
        <siteMapNode url="~/Vehicles/vehicles.aspx" title="Vehicles" testlevel="1"  description="Main vehicles page">
          <siteMapNode url="~/Vehicles/New_Vehicles.aspx" title="New Vehicles"></siteMapNode>
          <siteMapNode url="~/Vehicles/Used_Vehicles.aspx" title="Used Vehicles">
            <siteMapNode url="~/Vehicles/Side_Entry_Vehicles.aspx" title="Side Entry" />
            <siteMapNode url="~/Vehicles/Rear_Entry_Vehicles.aspx" title="Rear Entry" />
          </siteMapNode>
         ...
    </siteMap>
    

    Code in page (.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" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
    
      <xsl:template name="mapNode" match="/map:siteMapNode">
        <ul>
          <xsl:apply-templates select="map:siteMapNode"/>
        </ul>
      </xsl:template>
    
      <xsl:template match="map:siteMapNode">
    
        <li>
          <a href="{@url}">
            <xsl:value-of select="@title"/>
          </a>
          <xsl:if test="map:siteMapNode" >
            <xsl:call-template name="mapNode"/>
          </xsl:if>
        </li>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Code in page (.aspx)

          <div id="content">
                <ul>
                    <li>
                        <a href="#">Home Page</a>
                    </li>
                <%= MenuList %>
                </ul>
            </div>
    
            public string MenuList = string.Empty;
            protected void Page_Load(object sender, EventArgs e)
            {
                DataSet ds = new DataSet();
                ds.ReadXml(Server.MapPath("~/Web.sitemap"));
    
                string strXML = ds.GetXml();
                MenuList = GetHtml(Server.MapPath("MenuTest.xslt"), strXML);
            }
    
            public static string GetHtml(string xsltPath, string xml)
            {
                MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(xml));
                XPathDocument document = new XPathDocument(stream);
                StringWriter writer = new StringWriter();
                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load(xsltPath);
                transform.Transform(document, null, writer);
                return writer.ToString();
            }

    The screenshot:

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2015 6:11 AM
  • User846546683 posted

    This provides me a new avenue of approach. I had not considered the asp.net side of the equation.

    Thank you

    Tuesday, April 28, 2015 10:24 AM
  • User846546683 posted

    Thanks again. Your solution really did help me out.

    There's just one tweak I had to apply to make sure that the root node wasn't included (bolded in the script quote).  In this case, I required that the specific sitemap node with the title attribute of "Homepage" not be included. It would be nice if there was a more generic way to do this, but at least it did the job in this specific case.

        <xsl:template match="map:siteMapNode[@title!='Homepage']">
    <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" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
    
        <xsl:template name="mapNode" match="/map:siteMapNode">
            <ul>
                <xsl:apply-templates select="map:siteMapNode"/>
            </ul>
        </xsl:template>
    
        <xsl:template match="map:siteMapNode[@title!='Homepage']">
            <li>
                <a href="http://fnssnvtestsite.com{substring(@url, 2)}">
                    <xsl:value-of select="@title"/>
                </a>
                <xsl:if test="map:siteMapNode">
                    <xsl:call-template name="mapNode"/>
                </xsl:if>
            </li>
        </xsl:template>
    </xsl:stylesheet>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2015 2:09 AM