View Navigation With XSL
What is it with XSL? It's one of those languages that you use so infrequently that, each time you do, you face the same learning curve as the last time. Or maybe that's just me.
Yesterday I was playing with XSL again. Once I'd got back up the curve I had some fun seeing what I could do with Domino's View XML, sorry, DXL. It's amazing what you can do with XSL(T?).
Remember my article called Sensible Web Navigation? It described how to work out the number of documents in a view, so that we can work out whether to show the next/previous page links.
Well you can do this fairly easily with the DXL for a view. The image on the right shows a snippet DXL for this site's Feedback view. The URL used to get the XML is like:
/store.nsf/feedback?readviewentries&start=23&count=10
Notice a couple of things in the XML: the root node (viewentries) contains the "toplevelentries" parameter, which tells us how many documents are in the view. Plus, each document's node (viewentry) has a "position" attribute to tell us its place in the view. Using this information we can create the Next/Previous links using XSL. Here's how.
First thing we need is three variables in our XSL:
<xsl:variable name="ViewTotal" select="number(/viewentries/@toplevelentries)" />
<xsl:variable name="ViewPageStart" select="number(//viewentry[1]/@position)"/>
<xsl:variable name="ViewPageEnd" select="number(//viewentry[last()]/@position)"/>
Using these values we can decide whether to add a More » link. Like so:
<xsl:if test="$ViewPageEnd < $ViewTotal">
<xsl:element name="a">
<xsl:attribute name="href">feedback?OpenView&start=<xsl:value-of select="$ViewPageEnd + 1"/>&count=10</xsl:attribute>
<xsl:text disable-output-escaping="yes">More &raquo;</xsl:text>
</xsl:element>
</xsl:if>
The code for the « Previous is too similar to bother showing. Easy though ain't it?!
Why was I doing this? Well, I needed to fetch a user's email from their Mail database and display it as a "view" in a website. At some point I'll try and package the code in to a sample database and write an article called View Navigation With XSL. In the mean time, if you want to read about XSL and see some example code, this is a good place to start.
Not sure if you've seen this article, but it's along the same lines (view navigation) using AJAX.
{Link}
Comment 2 to that article says yes he has! =)
Dangit' all. I was gonna start looking at this after the Tour De France was done. Darn OLN coverage in the evening keeps me too busy to look at stuff like this. =/
I can't wait to dive into it!
Yeah, I've seen Bob's article. It's a good'en. But it's quite different to what I've been doing, although still similar.
I like both articles enough that I will combine them today. An AJAX request to readviewentries, XSLT to organize, and the different nav format.
Good stuff, and another RSS feed!!
OFF TOPIC (but a very cool concept that could work well for Domino developers):
{Link}
{Link}
{Link}
{Link}
{Link}
http://free.corefusion.net/Free/wausau/home.nsf/$$NavigatorTemplateDefault?OpenForm
{Link}
{Link}
{Link}
{Link}
{Link}
{Link}
{Link}