Umbraco XSLT。动态菜单

时间:2013-11-07 15:12:23

标签: xslt xpath umbraco

我的Umbraco项目有以下结构:

Content
-Home
--Contacts
--Offices
-About

Home有'/'地址,是一个索引页面。 有人可以告诉我如何通过XSLT将Both - Home和About元素放入菜单中吗? 目前我只能按当前页面的级别(即Home)获取子节点,因此我只获得联系人和办公室。我无法接受documentType,因为我想要一个动态的,而不是硬编码的。 有没有办法让Home和About不断显示在菜单中? 我完全是XSLT的新手,第二天是Umbraco本身。

编辑:这是XML的一部分,在

<xsl:param name="currentPage"/>

<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>

<xsl:template match="/">

<!-- The fun starts here -->
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:if test="$currentPage/@id = @id">
        <li class="selected">
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    </xsl:if>
    <xsl:if test="$currentPage/@id != @id">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    </xsl:if>
    <xsl:value-of select="$currentPage/id"/>
</xsl:for-each>
</ul>

</xsl:template>

Edit2:通过取消等级,我得到了“自我”,这是“家”,但仍然没有“关于”。 也许您知道如何找到有关“X-Path”选择器的信息,例如“ancestor-or-self :: *”?

1 个答案:

答案 0 :(得分:4)

我最终找到了答案。 通过项目根元素访问所有元素的方法是使用“$ currentPage / ancestor :: root // *”。 这就是我的标记现在在约翰的帮助下看起来如何简化“if”语句。

<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>

<xsl:template match="/">

<!-- The fun starts here -->
<ul>
    <xsl:for-each select="$currentPage/ancestor::root//*  [@level = $level and name() != 'Home' and @isDoc and string(umbracoNaviHide) != '1']">
        <li>
            <xsl:if test="$currentPage/@id = @id">
                <xsl:attribute name="class">selected</xsl:attribute>
            </xsl:if>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    <xsl:value-of select="$currentPage/id"/>
</xsl:for-each>
</ul>

在退出时,我得到的所有元素都是“内容”,除了“主页”(我只是不需要在我的菜单中)。

相关问题