在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() >= $FirstRow and position() <= $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() >= $FirstRow and position() <= $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()<= 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>