如何在SharePoint DVWP的xsl:for-each中添加AND过滤条件?
你之前用$Rows1 | $Rows2是取两个节点集的并集(OR逻辑),这就是为什么达不到AND过滤的效果。要实现LinkSection包含Training且SubSection包含Education的同时满足,直接在同一个XPath过滤表达式里用and运算符连接两个条件即可。
修正后的完整代码
<xsl:template name="dvt_1"> <xsl:variable name="dvt_StyleName">Table</xsl:variable> <!-- 合并AND条件到单个XPath表达式 --> <xsl:variable name="FilteredRows" select="/dsQueryResponse/Rows/Row[contains(@LinkSection,'Training') and contains(@SubSection,'Education')]"/> <div class="page_home" style=" height: 120px; overflow: hidden; z-index: 0;border:1px solid #CCCCCC;"> <div class="cat_heading" style="padding: 5px 10px; text-align: left; "> <h2 style="font-weight:bold"> <a title="Section 1">Section 1</a> </h2> </div> <div class="cat_imglinks" style=" height: 70px; overflow: hidden;"> <div class="cat_img" style="text-align: left; vertical-align: middle;"> <a> <span style="width: 78%; float: left;">Section 1 Text</span> </a> </div> <div class="panel cat_links"> <ul> <!-- 使用合并后的过滤节点集 --> <xsl:for-each select="$FilteredRows"> <li><a href="{@Link}" title="{@Title}"> <xsl:value-of select="@Title" disable-output-escaping="yes"/></a></li> </xsl:for-each> </ul> </div> </div> </div> </xsl:template>
关键修改点
- 移除了多余的
Rows1和Rows2变量,用单个FilteredRows变量存储同时满足两个条件的节点集 - 在XPath的
Row[]过滤中,用and连接两个contains()判断,实现AND逻辑 - 后续的
<xsl:for-each>直接使用这个合并后的变量即可
内容的提问来源于stack exchange,提问作者Kelsnz
相关产品推荐
相关产品推荐

