DNN DDRMenu:显示rootlevel的xslt模板

时间:2014-04-10 03:53:02

标签: xml xslt dotnetnuke breadcrumbs ddrmenu

我正在使用DDRMenu XSLT模板为DotNetNuke 7开发面包屑。

我正在使用的代码工作正常但是我想显示面包屑的根级别而不用硬编码。

我现在的面包屑是:

    News & Publications / Speeches / Test123

News& Publications是我菜单的子页面,我想要实现的是显示根级别

    Home / News & Publications / Speeches / Test123

这是我的XSLT模板

<?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>

这是输入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>

以下是菜单组件使用的示例XML

<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>

1 个答案:

答案 0 :(得分:1)

而不是这样做以获取面包屑

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

尝试这样做以获得 root 下的第一个节点

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

请注意,union运算符|只会获得不同的元素,这样如果“root”节点也被标记为痕迹,它将不会被选中(并输出)两次。