0

我正在尝试在 Composite C1 中为 Bootstrap 框架创建一个导航菜单,但我不确定如何让子菜单显示在菜单中。这是我所拥有的

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
    xmlns:lang="http://www.composite.net/ns/localization/1.0"
    xmlns:f="http://www.composite.net/ns/function/1.0"
    xmlns="http://www.w3.org/1999/xhtml"
    exclude-result-prefixes="xsl in lang f">
  <xsl:param name="sitemap" select="/in:inputs/in:result[@name='SitemapXml']/Page" />
  <xsl:template match="/">
    <html>
      <head>
      </head>
      <body>
        <div class="container">
          <div class="navbar">
            <div class="navbar-inner">
              <ul class="nav">
                <xsl:for-each select="$sitemap[@isopen='true']">
                  <li>
                    <a href="{@URL}">
                      <xsl:if test="@iscurrent='true'" >
                        <xsl:attribute name="class">active</xsl:attribute>
                      </xsl:if>
                      <xsl:value-of select="@MenuTitle" />
                    </a>
                  </li>
                  <xsl:apply-templates select="Page" />
                </xsl:for-each>
              </ul>             
            </div>
          </div>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Page">
    <xsl:if test="count(@MenuTitle)">
      <li>
        <a href="{@URL}">
          <xsl:if test="@isopen='true'" >
            <xsl:attribute name="class">active</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@MenuTitle" />
        </a>
      </li>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

我不确定我需要添加什么来获得子菜单。建议?

4

1 回答 1

1

试试这样的东西

<xsl:template match="/">
<html>
  <head>
  </head>
  <body>
    <div class="container">
      <div class="navbar">
        <div class="navbar-inner">
          <ul class="nav">
            <xsl:for-each select="$sitemap[@isopen='true']">
              <li>
                 <xsl:if test="@iscurrent='true'" >
                    <xsl:attribute name="class">active</xsl:attribute>
                 </xsl:if> 
                <a href="{@URL}">
                  <xsl:value-of select="@MenuTitle" />
                </a>
              </li>
              <xsl:apply-templates select="Page" />
            </xsl:for-each>
          </ul>             
        </div>
      </div>
    </div>
  </body>
</html>
</xsl:template>

<xsl:template match="Page">
<xsl:variable name="depth" select="@Depth" /> 
<xsl:variable name="isDropDown" select="count(./*) > 0 and $depth &lt; 3" />  
<xsl:if test="count(@MenuTitle)">
  <li>
    <xsl:if test="@isopen='true'" >
        <xsl:attribute name="class">active</xsl:attribute>
     </xsl:if>
     <xsl:if test="$isDropDown" >
        <xsl:attribute name="class">dropdown</xsl:attribute>
     </xsl:if> 
    <a href="{@URL}">
        <xsl:if test="$isDropDown" >
            <xsl:attribute name="class">dropdown-toggle</xsl:attribute>
        </xsl:if> 
        <xsl:if test="$isDropDown" >
            <xsl:attribute name="data-toggle">dropdown</xsl:attribute>
        </xsl:if> 
        <xsl:value-of select="@MenuTitle" />
         <xsl:if test="$isDropDown" >
            <b class="caret"></b>
        </xsl:if> 
    </a>
    <xsl:if test="$isDropDown">
        <ul class="dropdown-menu">
            <xsl:apply-templates select="./*" />
        </ul>
    </xsl:if>
  </li>
</xsl:if>

于 2013-01-22T10:14:45.587 回答