2012-08-01 63 views
1

我有一個Umbraco中的內容樹,我有3個主頁與他們的子頁面。我也有5個是首頁的孩子,他們有2個選項設置其他網頁:umbIsChildOfHomePage = 1和umbracoNaviHide = 1 看看結構: enter image description hereXslt選擇條件,如何生成2ndLevelNavigation?

現在:我要爲每一個頁面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 select。我怎麼做? 這是我試過的。我將它附加到模板中,因爲我不知道如何在其他選擇中附加條件。

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

問題是,即使我去了一個沒有孩子的網頁的網頁,即使是沒有孩子的網頁也會顯示。 如何使選擇個性化,以便僅當具有2個參數(showNavi和isHomePageChild)的頁面設置爲true時才顯示? 感謝您的幫助。 希望你理解這個問題。

回答

1

最初的代碼是從上而下,以水平目標節點「2」 - 這聽起來你想要的東西是正確的,你只需要讓它呈現出

有你正在嘗試什麼good example here去做。

,去掉了解下來($級別設置爲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> 

等等...