2013-05-22 78 views
1

我有一個側邊欄菜單,可以在li中創建div。ASP.NET if語句創建div

我遇到的問題是,如果菜單中的項目處於活動狀態,則不應在其之前創建不活動的div。即:它應該只有<li><div></div></li>,而不是<li><div></div><div></div></li>

 <xsl:if test="number(ParentEntityID) = 0 and EntityID!=$pCatID"> 
     <div class="inactive"> 
      <!--<a href="{concat('c-',EntityID,'-',SEName,'.aspx')}" style="color:black">--> 
      <xsl:choose> 
      <xsl:when test="count(child::Entity)=0"> 

       <a href="{concat('c-',EntityID,'-',SEName,'.aspx')}" style="color:black"> 
       <xsl:value-of select="$eName"/> 
       </a> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:choose> 
       <xsl:when test="EntityID=$ParentCategoryID"> 
        <div class="active"> 
        <xsl:value-of select="$eName"/> 
        </div> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:value-of select="$eName"/> 
       </xsl:otherwise> 
       </xsl:choose> 
      </xsl:otherwise> 
      </xsl:choose> 

      <!--</a>--> 
     </div> 
     </xsl:if> 

輸出:

<li> 
    **<div class="inactive">** 
    <div class="active"> 
    Active item 
    **</div>** 
    </div> 
</li> 
<li> 
    <div class="inactive"> 
    Inactive item 
    </div> 
</li> 

因此不主動DIV之外創建無效DIV,只應創建它是無效的,必須有什麼在上面的代碼改變?我把這些線放在**中,不應該在那裏。

我知道它與妥善安排test="EntityID=$ParentCategoryID"if陳述有關,但無法弄清楚。

+0

什麼變量告訴你一個項目是活動的? –

+0

@LenielMacaferi:顯然有更多的代碼,但如何停止在活動類div之外創建的空div的一般問題? '$ ParentCategoryID'是一個活動的。 – Dave

回答

0

這個版本呢?

<xsl:if test="number(ParentEntityID) = 0 and EntityID!=$pCatID"> 
     <xsl:choose> 
     <xsl:when test="count(child::Entity)=0"> 
      <a href="{concat('c-',EntityID,'-',SEName,'.aspx')}" style="color:black"> 
      <xsl:value-of select="$eName"/> 
      </a> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:choose> 
      <xsl:when test="EntityID=$ParentCategoryID"> 
       <div class="active"> 
       <xsl:value-of select="$eName"/> 
       </div> 
      </xsl:when> 
      <xsl:otherwise> 
       <div class="inactive"> 
       <xsl:value-of select="$eName"/> 
       </div> 
      </xsl:otherwise> 
      </xsl:choose> 
     </xsl:otherwise> 
     </xsl:choose> 
    </xsl:if> 
+0

謝謝!剛纔非活動的div從非活動項目中丟失:) – Dave

+0

更改了代碼... :) –

+0

完美!通過將不活動的div放置在'when test =「count(child :: Entity)= 0'語句中而不是外部,但我沒有做到:)你的修復工作正常:D謝謝!! – Dave