简体   繁体   English

在XSLT / Umbraco中进行每次检查之前检查项目计数

[英]Check item count before for-each in XSLT / Umbraco

I am working with XSLT files in an Umbraco solution. 我正在Umbraco解决方案中使用XSLT文件。

I want the entire ul tag to disappear if there is no elements to be shown: 如果没有要显示的元素,我希望整个ul标签消失:

<ul>
  <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/child::* [@isDoc and string(umbracoNaviHide) != '1']">
    <li>
      <a href="{umbraco.library:NiceUrl(@id)}" class="menuitem">
        <xsl:value-of select="@nodeName"/>
      </a>
    </li>
  </xsl:for-each>
</ul>

How can I make a IF statement that skips the entire codeblock if the foreach loop has no items? 如果foreach循环中没有项目,如何制作一个跳过整个代码块的IF语句?

Try putting the nodes you are going to select in a variable first, and then wrapping the output of a ul element in an xsl:if where you test the number of nodes. 尝试先将要选择的节点放入变量中,然后将ul元素的输出包装在xsl:if中,以测试节点数。

Something like this should do: 这样的事情应该做:

<xsl:variable name="children" select="umbraco.library:GetXmlNodeById($source)/child::* [@isDoc and string(umbracoNaviHide) != '1']" />
<xsl:if test="count($children) > 0">
   <ul>
     <xsl:for-each select="$children">
       <li>
         <a href="{umbraco.library:NiceUrl(@id)}" class="menuitem">
           <xsl:value-of select="@nodeName"/>
         </a>
       </li>
     </xsl:for-each>
  </ul>
</xsl:if> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM