如何在XSLT中进行分页 [英] How to make pagination in XSLT

查看:87
本文介绍了如何在XSLT中进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XSLT:

<xsl:template match="/">        
  <div id="dokumentliste">
    <xsl:variable name="alleNyheder" select="$currentPage//node" />

    <xsl:for-each select="$alleNyheder">
    <xsl:sort data-type="text" select="@createDate" order="descending" />            

        <xsl:if test="./data[@alias='manchet'] != ''">
            <div class="newsitem">
                <h2>
                    <xsl:value-of select="./data[@alias='title']"/>
                </h2>

                <xsl:if test="./data[@alias = 'manchet'] != ''">
                    <div class="nyhedContent">
                        <p>
                            <span class="dokumentListeDato">
                                <xsl:choose>
                                    <xsl:when test="./data[@alias='date'] != ''">
                                        <xsl:value-of select="umbraco.library:FormatDateTime(./data[@alias='date'], 'dd. MMMM yyyy')"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="umbraco.library:FormatDateTime(./@createDate, 'dd. MMMM yyyy')"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </span>
                            <xsl:value-of select="./data[@alias = 'manchet']"/>
                        </p>
                    </div>
                </xsl:if>
                <div class="dokumentListe_laes_mere">
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        Læs mere<img src="/frontend/images/macro/macro_laes_mere.png" alt="Læs mere"/>
                    </a>
                </div>
            </div>
            <!-- End newsitem -->
        </xsl:if>
      </xsl:for-each>
   </div> 
 </xsl:template>

我正在制作新闻列表,并希望进行某种分页.与Google几乎相同.您知道通常的".

I am making a newslist, and would like to make some sort of pagination. Almost the same one as seen on Google. You know "the usual one".

但是我不知道该怎么做.

But I can't figure out how to do this.

每个页面上的newsitems数量并不那么重要,但可以说每个页面上有10个.当显示10个第一个newsitems时,我想显示分页.用数字的左右两侧的下一个"和上一个"按钮.

The number of newsitems on each page isn't that important, but lets say 10 on each page. When the 10 first newsitems are shown, I would like the pagination to show up. With the "Next" and "Previous" buttons to the right and the left of the numbers.

有可能做到这一点,我是否已经对我的问题做了足够好的解释?我顺便使用了Umbraco CMS:)

Is it possible to make this, and have I explained my problem good enough? I use the Umbraco CMS by the way :)

非常感谢您.

-金

推荐答案

类似以下内容: 我还在那里留下了一些代码来处理您列表中的图片:-)

Something like this: I've left some code in there for dealing with images in your listing too :-)

<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
    <xsl:variable name="recordsPerPage" select="2"/>
    <xsl:variable name="pageNumber">
        <xsl:choose>
            <!-- first page -->
            <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
            <!-- what was passed in -->
            <xsl:otherwise>
                <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>

    <!-- The fun starts here -->

    <xsl:call-template name="pagination">
        <xsl:with-param name="pageNumber" select="$pageNumber"/>
        <xsl:with-param name="recordsPerPage" select="$recordsPerPage" />
        <xsl:with-param name="numberOfRecords" select="$numberOfRecords" />
    </xsl:call-template>

<ul class="listing self-clear">
        <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
            <xsl:sort order="descending" select="data[@alias='releasedOn']"></xsl:sort>

            <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) + $recordsPerPage )">
                <li>
                    <xsl:attribute name="class">
                        <xsl:if test="data[@alias='image'] = ''">
                            no-img
                        </xsl:if>
                        <xsl:if test="position() = $recordsPerPage * (number($pageNumber) + 1)">
                            last
                        </xsl:if>
                    </xsl:attribute>
                    <h3>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName"/>
                        </a>
                    </h3>
                    <xsl:if test="data[@alias='image'] != ''">
                        <img src="{data[@alias='image']}" class="drop-shadow" />
                    </xsl:if>
                    <p class="date"><xsl:value-of select="umbraco.library:LongDate(data[@alias='releasedOn'])"/></p>
                    <xsl:value-of select="data[@alias='abstract']" disable-output-escaping="yes"/>
                    <a href="{umbraco.library:NiceUrl(@id)}" class="read-more">Read More</a>
                </li>
            </xsl:if>
        </xsl:for-each>
    </ul>

    <xsl:call-template name="pagination">
        <xsl:with-param name="pageNumber" select="$pageNumber"/>
        <xsl:with-param name="recordsPerPage" select="$recordsPerPage" />
        <xsl:with-param name="numberOfRecords" select="$numberOfRecords" />
    </xsl:call-template>

</xsl:template>

<xsl:template name="pagination">
    <xsl:param name="pageNumber"/>
    <xsl:param name="recordsPerPage"/>
    <xsl:param name="numberOfRecords"/>

    <div class="pagination">
    <div class="wrapper">

        <xsl:if test="(($pageNumber +1 ) * $recordsPerPage) &lt; ($numberOfRecords)">
            <a href="?page={$pageNumber +1}" class="next">Next</a>
        </xsl:if>

        <xsl:if test="$pageNumber &gt; 0">
            <a href="?page={$pageNumber -1}" class="prev">Prev</a>
        </xsl:if>

        <span class="page-nos">
        Page
        <xsl:call-template name="for.loop">
            <xsl:with-param name="i">1</xsl:with-param>
            <xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
            <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>
        </span>

    </div>
    </div>
</xsl:template>

<xsl:template name="for.loop">
    <xsl:param name="i"/>
    <xsl:param name="count"/>
    <xsl:param name="page"/>
    <xsl:if test="$i &lt;= $count">
        <span>
        <xsl:if test="$page != $i">
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}" >
                <xsl:value-of select="$i" />
            </a>
        </xsl:if>
        <xsl:if test="$page = $i">
            <xsl:value-of select="$i" />
        </xsl:if>
        </span>
    </xsl:if>

    <xsl:if test="$i &lt;= $count">
        <xsl:call-template name="for.loop">
            <xsl:with-param name="i">
                <xsl:value-of select="$i + 1"/>
            </xsl:with-param>
            <xsl:with-param name="count">
                <xsl:value-of select="$count"/>
            </xsl:with-param>

            <xsl:with-param name="page">
                <xsl:value-of select="$page"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:if>
</xsl:template>

这篇关于如何在XSLT中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆