如何在 XSLT 中进行分页

发布于 2024-08-05 06:06:09 字数 2352 浏览 4 评论 0原文

我有以下 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>

我正在制作新闻列表,并且想要进行某种分页。和谷歌上看到的几乎一模一样。你知道“平常的”。

但我不知道该怎么做。

每个页面上的新闻站点数量并不那么重要,但假设每个页面上有 10 个。当显示前 10 个新闻站点时,我希望显示分页。数字右侧和左侧有“下一个”和“上一个”按钮。

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

非常感谢。

-金

I have the following 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>

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.

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.

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

Thank you very much.

-Kim

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一紙繁鸢 2024-08-12 06:06:09

像这样的东西:
我也在那里留下了一些代码来处理您列表中的图像:-)

<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') <= 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() > $recordsPerPage * number($pageNumber) and position() <= 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) < ($numberOfRecords)">
            <a href="?page={$pageNumber +1}" class="next">Next</a>
        </xsl:if>

        <xsl:if test="$pageNumber > 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 <= $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 <= $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>

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') <= 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() > $recordsPerPage * number($pageNumber) and position() <= 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) < ($numberOfRecords)">
            <a href="?page={$pageNumber +1}" class="next">Next</a>
        </xsl:if>

        <xsl:if test="$pageNumber > 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 <= $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 <= $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>
与之呼应 2024-08-12 06:06:09

我现在明白了这一点。我可以看到您刚刚复制/粘贴了 Tim Geyssens 制作的分页: http:// /www.nibble.be/?p=11

代码也不错,但我更改了其中一些以使其正常工作。我不知道我是否应该接受我自己的答案作为正确的答案,Myster 的答案作为正确的答案,或者我是否可以删除这篇文章?

I figured this one out now. I can see that you have just copy/pasted the pagination that where made by Tim Geyssens here: http://www.nibble.be/?p=11

And the code is also kind'a good, but I changed some of it to get it working. I don't know if I should just accept my own answer as the right one, the answer from Myster as the right one or if I can delete this post?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文