1

在 SharePoint 2013 中,使用数据视图 XSLT Web 部件我想限制每个项目的行数(而不是一般返回的项目数)。我在 JavaScript 中提出了一些建议来查找 div 高度并将其划分为 line height 属性,但是由于我使用的是 XSL,我想知道是否还有其他方法?我也在 CSS 中寻找了一些解决方案,但那里什么也没有。

这是 XSLT(我想限制从 div "AdministrativePosts" 获得的行数):

<Xsl>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">&apos;</xsl:param>
<xsl:param name="ManualRefresh"></xsl:param><xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<xsl:choose>
<xsl:when test="($ManualRefresh = 'True')">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td valign="top">
                        <xsl:call-template name="dvt_1"/>
                    </td>
                    <td width="1%" class="ms-vb" valign="top">
                        <img src="/_layouts/15/images/staticrefresh.gif" id="ManualRefresh" border="0" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" alt="Click here to refresh the dataview."/>
                    </td>
                </tr>
            </table>
        </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="dvt_1"/>
        </xsl:otherwise>
                </xsl:choose>
</xsl:template>

            <xsl:template name="dvt_1">
                <xsl:variable name="dvt_StyleName">Table</xsl:variable>
                <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
                <xsl:variable name="RowLimit" select="1" />
                <div class="AdministrativePosts">                   
                    <xsl:call-template name="dvt_1.body">
                        <xsl:with-param name="Rows" select="$Rows"/>
                        <xsl:with-param name="FirstRow" select="1" />
                        <xsl:with-param name="LastRow" select="$RowLimit" />
                    </xsl:call-template>
            </div>
        </xsl:template>
                <xsl:template name="dvt_1.body">
                    <xsl:param name="Rows"/>
                    <xsl:param name="FirstRow" />
                    <xsl:param name="LastRow" />
                    <xsl:for-each select="$Rows">
                        <xsl:variable name="dvt_KeepItemsTogether" select="false()" />
                        <xsl:variable name="dvt_HideGroupDetail" select="false()" />
                        <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether">
                            <xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
                                <xsl:call-template name="dvt_1.rowview" />
                        </xsl:if>
                    </xsl:if>
                </xsl:for-each>
</xsl:template>
                            <xsl:template name="dvt_1.rowview">     
            <xsl:value-of select="@Body" disable-output-escaping="yes"/>
    </xsl:template>
        </xsl:stylesheet></Xsl>

结果如下:

Lorem Ipsum 只是印刷和排版行业的虚拟文本。自 1500 年代以来,Lorem Ipsum 一直是行业的标准虚拟文本,当时一位不知名的印刷商采用了一种类型的厨房并将其加扰以制作一本类型样本书。它不仅经历了五个世纪,而且经历了电子排版的飞跃,基本保持不变。它在 1960 年代随着包含 Lorem Ipsum 段落的 Letraset 表的发布而流行起来,最近还随着 Aldus PageMaker 等桌面出版软件(包括 Lorem Ipsum 的版本)而普及。

但我希望它只显示前五行,不管 div 的宽度是多少,所以字符限制在这里不起作用。

4

1 回答 1

1

但我希望它只显示前五行,不管 div 的宽度是多少,所以字符限制在这里不起作用。

你不是一个人。以下是一些类似的问题:

祝你好运。

参考

于 2013-08-26T13:51:25.137 回答