2012-07-23 68 views
1

我有一個網站,其頁面和子頁面如附圖所示。 enter image description here如何使用xslt顯示站點的站點地圖/導航?

某些子頁面屬於First Pagge(關於Patient Direct),它們設置爲「不在菜單中顯示」。

好吧,我要讓這將生成一個HTML內容像這樣的XSLT文件:

菜單項1(包括首頁 - 關於患者直接)

-submenu第1頁1

菜單項2(包括首頁 - 關於患者直接)

-submenu第2頁1

-submenu第2頁2

我該怎麼做?

這是我迄今爲止

<?xml version="1.0" encoding="UTF-8"?> 

]>

<xsl:output method="xml" omit-xml-declaration="yes" /> 

<xsl:param name="currentPage"/> 

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

<xsl:template match="/"> 

    <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id"> 
     <div class="column"> 
      <h1> 
       <a href="#"> 
        Home Page - I don't know what to write here 
       </a> 
      </h1> 
      </div>  
    </xsl:if> 

     <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> 
     <div class="column"> 
      <h1> 
       <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> 
      </h1> 
      </div> 
     </xsl:for-each> 

</xsl:template> 

我也打開了http://our.umbraco.org/forum/developers/xslt/33326-How-to-display-sitemapnavigation-for-a-site-using-xslt

回答

3

的討論,我終於成功了去做 我一直在尋找的東西。這裏是爲那些誰可能會尋找相同的功能代碼

<?xml version="1.0" encoding="UTF-8"?> 

]>

<xsl:template name="menu"> 
    <xsl:param name="level"/> 

    <xsl:variable name="RootNode" select="umbraco.library:GetXmlNodeById(1050)" /> 
    <div class="column"> 
     <h1> 
      <a href="{umbraco.library:NiceUrl($RootNode/@id)}" style="width:200px;"> 
       <xsl:value-of select="$RootNode/@nodeName"/> 
      </a> 
     </h1> 
     <xsl:call-template name="submenu_Homepage"> 
     </xsl:call-template> 

    </div> 

    <xsl:if test="count($currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'"> 
     <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> 
      <div class="column"> 
       <h1> 
        <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> 

       </h1> 

       <xsl:if test="count(current()/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'"> 
        <xsl:call-template name="submenu"> 
         <xsl:with-param name="level" select="$level+1"/> 

        </xsl:call-template> 
       </xsl:if> 
      </div> 
     </xsl:for-each> 
    </xsl:if> 

</xsl:template> 

<xsl:template name="submenu"> 
    <xsl:param name="level"/> 
    <ul class="level_{@level}"> 
     <xsl:for-each select="current()/*[@isDoc and string(umbracoNaviHide) != '1']"> 
      <li> 
       <xsl:if test="position() != last()"> 
        <xsl:attribute name="class">bottom_border</xsl:attribute> 
       </xsl:if> 
       <a href="{umbraco.library:NiceUrl(@id)}"> 
        <xsl:value-of select="@nodeName"/> 
       </a> 
       <!--case when we have third menu level--> 
       <xsl:if test="count(current()/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'"> 
        <xsl:call-template name="submenu"> 
         <xsl:with-param name="level" select="$level+1"/> 
        </xsl:call-template> 
       </xsl:if> 
      </li> 
     </xsl:for-each> 
    </ul> 
</xsl:template> 

<xsl:template name="submenu_Homepage"> 
    <ul> 
     <xsl:for-each select="$currentPage/ancestor-or-self::*/* [@isDoc and string(umbracoNaviHide) = '1']"> 
      <li> 
       <xsl:if test="position() != last()"> 
        <xsl:attribute name="class">bottom_border</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> 
    </ul> 
</xsl:template> 

+0

您還可以訪問http://how-to-code-net.blogspot.ro/2012/07/how-to-create-sitemap-for-website-in.html瞭解更多詳情 – 2012-07-23 12:09:49