xsl 1.0实现控制dataview webpart每个分组里最大显示条数

本文介绍了一种在Dataview中实现分组显示的方法,通过调整XSLT模板,可以更好地控制每个分组内显示的数据条数。这种方法涉及自定义分组头部模板和行视图模板,并使用XSLT变量和条件逻辑来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在data view 里,分组实现的原理是这样:

获得一个排好序的Rows,然后在for-each的时候,如果发现分组字段值发生改变,调用一下groupheader的template生成一行分组信息。这样我们要控制他每个分组的最大个数就不是很容易。

我们可以如下实现:

在每个分组调用groupheader的when里,调用一下:

<xsl:variable name="GroupRows" select="/dsQueryResponse/Rows/Row[(@groupfield)=$groupheader0]"/>

然后for-each这个GroupRows调用row view的template.即: 在每个调用groupheader的template的时侯将所有的该组的信息直接一起打出来。然后在row view里通过position()来控制你想要显示的条数。

示例代码如下:

<xsl:template name="dvt_1.body">
  <xsl:param name="Rows"/>
  <xsl:param name="FirstRow" />
  <xsl:param name="LastRow" />
  <xsl:variable name="dvt_Rows">
   <root>
    <xsl:for-each select="$Rows">
     <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow)">
      <xsl:copy-of select="." />
     </xsl:if>
    </xsl:for-each>
   </root>
  </xsl:variable>
  <xsl:for-each select="$Rows">
   <xsl:variable name="NewGroup_0">
    <xsl:choose>
     <xsl:when test="not ($dvt_groupfield)">
      <xsl:value-of select="ddwrt:NameChanged(string(@Contract), 0)" />
     </xsl:when>
     <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
   </xsl:variable>
   <xsl:choose>
    <xsl:when test="0" />
    <xsl:when test="not($dvt_groupfield) and (not($NewGroup_0='') and position() &gt;= $FirstRow and position() &lt;= $LastRow or ($FirstRow = position()))">
     <xsl:variable name="groupheader0">
      <xsl:choose>
       <xsl:when test="not (@Contract) and (@Contract) != false()">
        <xsl:value-of select="' '" />
       </xsl:when>
       <xsl:otherwise>
        <xsl:value-of select="@Contract" />
       </xsl:otherwise>
      </xsl:choose>
     </xsl:variable>
     <xsl:if test="not ((position()=1) or (position()=$FirstRow))"></xsl:if>
     <xsl:call-template name="dvt_1.groupheader0">
      <xsl:with-param name="fieldtitle">Contract</xsl:with-param>
      <xsl:with-param name="fieldname">Contract</xsl:with-param>
      <xsl:with-param name="fieldvalue" select="$groupheader0" />
      <xsl:with-param name="fieldtype" select="'text'" />
      <xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((@Contract)=$groupheader0 or ((not(@Contract) or @Contract='') and $groupheader0=' '))]" />
      <xsl:with-param name="groupid" select="'0'" />
      <xsl:with-param name="displaystyle" select="'auto'" />
      <xsl:with-param name="imagesrc" select="'/_layouts/images/plus.gif'" />
      <xsl:with-param name="alttext" select="'expand'" />
      <xsl:with-param name="altname" select="'collapse'" />
      <xsl:with-param name="hidedetail" select="false()" />
      <xsl:with-param name="showheader" select="true()" />
      <xsl:with-param name="showheadercolumn" select="false()" />
     </xsl:call-template>
     <xsl:variable name="GroupRows" select="/dsQueryResponse/Rows/Row[(@Contract)=$groupheader0]"/>
     <xsl:for-each select="$GroupRows">
      <xsl:call-template name="dvt_1.rowview" />
     </xsl:for-each>
    </xsl:when>
   </xsl:choose>
   <xsl:variable name="BreakOut">
    <xsl:choose>
     <xsl:when test="not($dvt_groupfield) and position()=$LastRow+1">
      <xsl:value-of select="ddwrt:NameChanged('', -1)" />
     </xsl:when>
     <xsl:otherwise>BreakOut</xsl:otherwise>
    </xsl:choose>
   </xsl:variable>
   
  </xsl:for-each>

 </xsl:template>

<xsl:template name="dvt_1.rowview">
  <xsl:if test="position()&lt;= 10">
  <xsl:variable name="dvt_GroupStyle" select="'none'" />
  <tr style="display:{$dvt_GroupStyle}">
   <xsl:if test="position() mod 2 = 1">
    <xsl:attribute name="class">ms-alternating</xsl:attribute>
   </xsl:if>
   <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
    <td class="ms-vb" width="1%" nowrap="nowrap">
     <span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
    </td>
   </xsl:if>
   <td class="ms-vb">
    <xsl:value-of select="position()"/>
   </td>
   <td class="ms-vb">
    <xsl:value-of select="@。。。"/>
   </td>
   <td class="ms-vb">
    <xsl:value-of select="@。。。"/>
   </td>
   <td class="ms-vb">
    <xsl:value-of select="@。。。"/>
   </td>
  </tr>
  </xsl:if>
 </xsl:template>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值