【问题标题】:ASP.NET if statement creating divASP.NET if 语句创建 div
【发布时间】:2013-05-22 03:53:55
【问题描述】:

我有一个侧边栏菜单,可以在 li 中创建 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 语句有关,但就是想不通。

【问题讨论】:

  • 什么变量告诉你一个项目是活跃的?
  • @LenielMacaferi:显然需要更多代码,但一般问题是如何阻止在活动类 div 之外创建空 div? $ParentCategoryID 是活跃的。

标签: html asp.net xslt if-statement conditional-statements


【解决方案1】:

这个版本怎么样?

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

【讨论】:

  • 谢谢!刚才,非活动项目中缺少非活动 div :)
  • 完美!通过将非活动 div 放在 when test="count(child::Entity)=0 语句中而不是在外部,我确实做了你所做的,但这没有用 :) 你的修复工作:D 谢谢!!
  • 很高兴知道它有效!这就是我们所追求的……让事情按预期工作。 :D
猜你喜欢
  • 1970-01-01
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多