XML原子分页

时间:2015-06-03 15:28:09

标签: xslt atom-feed

我一直在搜索互联网,难以获得如何分页XML原子信息的线索,但没有成功。如何在页面上显示导航分页?即第1 2 .9页

<?xml version="1.0" encoding="utf-8" ?> 
<feed xmlns:s="http://feed.example.com/services" xmlns="http://www.w3.org/2005/Atom">
<title type="text">org select - with 'Field' in name</title> 
<id>http://feed.example.com/orga/srvic/name/Field</id> 
<rights type="text">Copyright 2015</rights> 
<updated>2010-05-09</updated> 
<category term="Search" /> 
<logo>http://www.org.uk/orgcservices/docs/logo.jpg</logo> 
<author>
<name>org select</name> 
<uri>http://www.sampleorg.uk</uri> 
<email>wbsrvcs@example.com</email> 
</author>

<link rel="self" type="application/atom+xml" title="org select - Practices with 'Field' in name" href="http://feed.example.com/organisations/services/name/Field?apikey=12345" /> 
<link rel="first" type="application/atom+xml" title="first" length="1000" href="http://feed.example.com/organisations/services/name/Field?apikey=12345&page=1" /> 
<link rel="next" type="application/atom+xml" title="next" length="1000" href="http://feed.example.com/organisations/services/name/Field?apikey=12345&page=2" /> 
<link rel="last" type="application/atom+xml" title="last" length="1000" href="http://feed.example.com/organisations/services/name/Field?apikey=12345&page=9" />

<tracking xmlns="http://feed.example.com/services"><img style="border: 0; width: 1px; height: 1px;" alt="" src="http://webtrendsample.com/dfgfgh56dgd5/ddds.gif?fffuri=/organisations%2fservices%2fname%2fField&wt.js=no&wt.cg_n=feed"/></tracking> 
<entry>
<id>http://feed.example.com/organisations/services/245645634</id> 
<title type="text">Field Tree House</title> 
<updated>2015-05-12T08:08:08Z</updated> 
<link rel="self" title="Field Tree House Surgery" href="http://feed.example.com/organisations/services/24308?apikey=12345" /> 
<link rel="alternate" title="Field Tree House Surgery" href="http://www.org.uk/Srvcs/DR/Default.aspx?id=34343434" /> 
<content type="application/xml">
<s:organisationSummary>
<s:name>Field Tree House</s:name> 
<s:odsCode>JD12345</s:odsCode> 
<s:address>
<s:addressLine>Field Tree House</s:addressLine> 
<s:addressLine>John Street</s:addressLine> 
<s:addressLine>Lirkam</s:addressLine> 
<s:addressLine>Stockion</s:addressLine> 
<s:postcode>DWQ4 22GW</s:postcode> 
</s:address>
<s:contact type="General">
<s:telephone>111 2223333444</s:telephone> 
</s:contact>
</s:organisationSummary>
</content>
</entry>

<entry>
.
.
.

我对XML没有多少经验,所以请耐心等待。我已经看到了这一点:Pagination in feeds like ATOM and RSS?但这并不能回答我的问题。任何想法的家伙。我真的很感激。

非常感谢你们。

1 个答案:

答案 0 :(得分:0)

由于你没有展示你的尝试,很难弄清楚你想要什么。如果你想在Atom提要中计算给定页面长度的页数,那么它就是简单的算术:

<xsl:variable name="page-length" select="10"/>

<xsl:template match="atom:feed">
   <xsl:variable name="total" select="count(atom:entry)"/>
   <xsl:choose>
      <xsl:when test="$total eq 0">
         <p>No entry.</p>
      </xsl:when>
      <xsl:otherwise>
         <p>
            <xsl:text>Pages: </xsl:text>
            <xsl:value-of select="(($total - 1) idiv $page-length) + 1"/>
         </p>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>