Question

I'm developing a breadcrumb for DotNetNuke 7 using the DDRMenu XSLT Templates.

The codes I am using are working fine however I want to display the rootlevel of the breadcrumbs without hardcoding it.

What I have in my breadcrumbs now is:

    News & Publications / Speeches / Test123

News&Publications is a subpage of my menu and what I'm trying to achieve is to show the rootlevel

    Home / News & Publications / Speeches / Test123

Here is my XSLT Template

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:param name="CSSClass">breadcrumb</xsl:param>
    <xsl:param name="separator"></xsl:param>
    <xsl:template match="/*">
        <xsl:apply-templates select="root" />
    </xsl:template>
    <xsl:template match="root">
            <xsl:apply-templates select="//node[@breadcrumb =1]" />
    </xsl:template>
    <xsl:template match="node">
        <li>
            <xsl:if test="position() != 1">
                <xsl:value-of select="$separator" disable-output-escaping="yes" />
            </xsl:if>
            <xsl:choose>
                <xsl:when test="@enabled = 1 and @selected !=1">
                    <a href="{@url}">
                        <xsl:value-of select="@text" />
                    </a>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="@text" />
                </xsl:otherwise>
            </xsl:choose>
        </li>
    </xsl:template>
</xsl:stylesheet>

This is the input XML.

<?xml version="1.0" encoding="utf-8" ?>
<manifest>
    <template>Breadcrumb.xslt</template>
    <stylesheets>
        <stylesheet>[MANIFEST]/breadcrumb.css</stylesheet>
    </stylesheets>
    <defaultTemplateArguments>
        <templateArgument name="CSSClass" value="breadcrumb" />
    </defaultTemplateArguments>
</manifest>

Below is the Example XML the menu component uses

<Root>
    <root>
        <node id="37" text="Home" url="http://www.dnndoneright.com/Home.T37.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="0" >
            <description >Upgrade your standard DNN menu - automatically and for free - to an SEO-optimised, accessible, mobile-friendly, cross-browser menu.</description>
        </node>

        <node id="56" text="DNN Menu" url="http://www.dnndoneright.com/DNN-Menu.T56.aspx" enabled="1" selected="0" breadcrumb="1" first="0" last="0" only="0" depth="0" >
            <node id="97" text="Menu features" url="http://www.dnndoneright.com/Menu-features.T97.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="1" />
            <node id="111" text="Pre-built templates" url="http://www.dnndoneright.com/Pre-built-templates.T111.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="1" >
                <node id="94" text="Standard DNN menu, upgraded" url="http://www.dnndoneright.com/Standard-DNN-menu-upgraded.T94.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
                <node id="124" text="Superfish template" url="http://www.dnndoneright.com/Superfish-template.T124.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="106" text="Treeview template" url="http://www.dnndoneright.com/Treeview-template.T106.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="107" text="Accordion template" url="http://www.dnndoneright.com/Accordion-template.T107.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="112" text="Dropdown template" url="http://www.dnndoneright.com/Dropdown-template.T112.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="96" text="Mega-menu" url="http://www.dnndoneright.com/Mega-menu.T96.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
            </node>
            <node id="113" text="Getting started" url="http://www.dnndoneright.com/Getting-started.T113.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="1" >
                <node id="114" text="Installing the menu" url="http://www.dnndoneright.com/Installing-the-menu.T114.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
                <node id="115" text="Upgrading a SolPart menu" url="http://www.dnndoneright.com/Upgrading-a-SolPart-menu.T115.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="116" text="Upgrading a DNNMenu" url="http://www.dnndoneright.com/Upgrading-a-DNNMenu.T116.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="117" text="Installing a template" url="http://www.dnndoneright.com/Installing-a-template.T117.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="118" text="Adding to a skin" url="http://www.dnndoneright.com/Adding-to-a-skin.T118.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
            </node>
            <node id="119" text="Customising templates" url="http://www.dnndoneright.com/Customising-templates.T119.aspx"   enabled="0" selected="0" breadcrumb="1" first="0" last="1" only="0" depth="1" >
                <node id="120" text="Standard options" url="http://www.dnndoneright.com/Standard-options.T120.aspx"         enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
                <node id="121" text="Specifying filenames" url="http://www.dnndoneright.com/Specifying-filenames.T121.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
                <node id="122" text="XML format" url="http://www.dnndoneright.com/XML-format.T122.aspx"                     enabled="1" selected="1" breadcrumb="1" first="0" last="0" only="0" depth="2" />
                <node id="123" text="Creating custom templates" url="http://www.dnndoneright.com/Creating-custom-templates.T123.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
            </node>
        </node>

        <node id="87" text="Download" url="http://www.dnndoneright.com/Download.T87.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="0" />

        <node id="85" text="Contact" url="http://www.dnndoneright.com/Contact.T85.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="0" >
            <node id="129" text="Blog" url="http://www.dnndoneright.com/Blog.T129.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="1" />
            <node id="130" text="Forum" url="http://www.dnndoneright.com/Forum.T130.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="1" />
        </node>
    </root>
</Root>
Was it helpful?

Solution

Instead of doing this to get the breadcrumbs

 <xsl:apply-templates select="//node[@breadcrumb =1]" />

Try doing this to get the firs node under root too

 <xsl:apply-templates select="node[@first=1]|//node[@breadcrumb =1]" />

Note the union operator | will only get distinct elements so that if the "root" node is also marked as a breadcrumb, it won't get selected (and output) twice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top