Re: [xsl] "re-calling" template part 2

Subject: Re: [xsl] "re-calling" template part 2
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 10 May 2007 12:13:07 +0200
Vaduvoiu Tiberiu wrote:
Ok, I'm going to try to explain what I need to do, hopeflly someone can give me at least a starting point or clue on how to do it. I have an xml like

<newslist>
       <news>
            <name>news1</name>
            <location>/folder/news1.xml</location>
        </news>
       <news>
            <name>news2</name>
            <location>/folder/news2.xml</location>
        </news>

...and so on up to news100 let's say.

I need to display the news names on a page 10 at the times(because there are to many and there are other issues that kind of force me to display only like 9 or 10). So when someone loads the page it sees just 10 news, like
news1
news2
...
news10

Under the div or table where the news names are displayed I should have 2 buttons or anchors "previous" and "next" and when the user clicks on the them, he sees the next 10 entries(news11,news12,etc) or the previous 10 on the page. Hope you see the picture. I'm thinking is not such a hard thing to achieve but so far I can't manage to make it work. Anyone can give me a clue on how this problem should be approched. 10x a lot

What you need is two things: one, an understanding of how Cocoon can help you building your web application and how it links your XML sources together and two, how XSLT can help you with it. To get what you want, I think a parameter is in order, which gives you the "from":


<!-- place this where you need it -->
<xsl:apply-templates select="news[position() > $from and position() &lt; $from + 10]" />
<a href="link-to-previous?from={$from - 10}">Previous</a>
<a href="link-to-next?from={$from + 10}">Next</a>


<!-- match the news items -->
<xsl:template match="news">
  <a href="link-to-news-item?id={$id}">
    <xsl:value-of select="name" />
  </a>
</xsl:template>

How you use this code and how you create your links and how this maps to your actions in Cocoon is, of course, totally up to you. Cocoon is not an easy framework and it requires quite some understanding of different techniques before you can master it.

P.S If anyone knows some documentation/tutorial/e-books on cocoon please give me a link cause I've been looking on google for tutorials/ebooks on cocoon and haven't found almost anything.

Google gave me these:
* ISBN 0764543555
* ISBN 0672322579
* ISBN 0735712352. The last one is also available as ebook: http://safari.oreilly.com/0735712352 (not sure of the others).
plus more...


Cheers,
-- Abel

Current Thread