Xslt选择条件,如何生成二级导航?

时间:2012-08-01 08:21:04

标签: xml xslt umbraco

我在Umbraco有一个内容树,我有3个主要页面及其子页面。我还有5个其他页面是主页的孩子,他们有2个选项集:umbIsChildOfHomePage = 1和umbracoNaviHide = 1 看看结构: enter image description here

现在:我想为每个页面生成一个umb2ndLevelNavigation。

我的xslt文件中有这个

<xsl:variable name="items" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 2]/* [@isDoc and string(umbracoNaviHide) != '1']"/>
    <xsl:if test="count($items) &gt; 0">
        <ul>
            <xsl:for-each select="$items">
                <li>
                    <xsl:if test="position() = last()">
                        <xsl:attribute name="class">last</xsl:attribute>
                    </xsl:if>
                    <xsl:if test="position() = 1">
                        <xsl:attribute name="class">first</xsl:attribute>
                    </xsl:if>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="@nodeName"/>
                    </a>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:if>

仅适用于主页以外的页面。 所以需要额外的个性化xslt选择。我怎么做? 这是我试过的。我将它附加到模板,因为我不知道如何在其他选择中附加条件。

<xsl:variable name="itemsHomepage" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 1]/* [@isDoc and string(umbracoNaviHide) = '1' and string(umbIsChildOfHomePage) = 1]"/>
    <xsl:if test="count($itemsHomepage) &gt; 0">
        <ul>
            <!--<xsl:attribute name="class">
               a<xsl:value-of select="$currentPage/parent::*[@isDoc]/@id [string(umbIsChildOfHomePage) = 1 ]" />
            </xsl:attribute>-->
            <xsl:for-each select="$itemsHomepage">
                <li>
                    <xsl:if test="position() = last()">
                        <xsl:attribute name="class">last</xsl:attribute>
                    </xsl:if>
                    <xsl:if test="position() = 1">
                        <xsl:attribute name="class">first</xsl:attribute>
                    </xsl:if>
                    <xsl:choose>
                        <xsl:when test="name() = 'Link'">
                            <a href="{current()/linkUrl}" target="_blank">
                                <xsl:value-of select="@nodeName" />
                            </a>

                        </xsl:when>
                        <xsl:otherwise>
                            <a href="{umbraco.library:NiceUrl(@id)}">
                                <xsl:value-of select="@nodeName" />
                            </a>
                        </xsl:otherwise>
                    </xsl:choose>
                </li>
            </xsl:for-each>
            <!--<li>
                s:<xsl:value-of select="$currentPage/@id" />
                <xsl:value-of select="$RootNode/@nodeName"/>-<xsl:value-of select="$RootNode/@id"/>
            </li>-->
        </ul>
    </xsl:if>

问题是,即使我没有孩子的页面也会显示没有孩子主页的页面。 如何仅在具有这两个参数(showNavi和isHomePageChild)的页面设置为true时才个性化选择以显示? 谢谢你的帮助。 希望你能理解这个问题。

1 个答案:

答案 0 :(得分:1)

初始代码将节点从上到下定位到“2”级 - 这听起来对你想要的是正确的,你只需要将它渲染出来

你要做的事情只有good example here

剥离该解决方案($ level设置为2)提醒我为什么我不会心甘情愿地再次靠近xslt!:

<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:if test="$currentPage/@id = current()/@id or $currentPage/../@id = current()/@id or $currentPage/../../@id = current()/@id">

...

<ul>
<!-- 1st navigation items -->
<xsl:for-each select="./child::* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"></xsl:if>
<li> .... </li>

<!--output 2nd level nevigation items -->
<xsl:if test="count(current()/child::* [@isDoc]) &gt; 0 and $currentPage/@id = current()/@id or $currentPage/../@id = current()/@id or $currentPage/../../@id = 
current()/@id">

<ul>
<!--output 3rd level nevigation items -->
<xsl:for-each select="./child::* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"></xsl:if>
<li> ... </li>

依旧......