Anonymous
Domino 2.0 Rich Internet Applications with IBM Lotus Notes/Domino
You are here: Today » From NotesView to XHTML with @formulas, XSLT or JavaScript
« Multilingual website and site navigation in Domino
Single page Ajax interface in Domino part 2 »

From NotesView to XHTML with @formulas, XSLT or JavaScript

In the HTML version of my blog, I use @formulas to build the 'Monthly archive' list in the right column. In the Ajax version, I can do it with JavaScript or with XSLT. So here is the same in all three ways.

@formulas

a:=@DbColumn(""; ""; "bymonth"; 1);
@If(@IsError(a); @Return(@Text(a)); "");
@If(@Elements(a)=0; @Return(""); "");

qm:=@If(@Middle(DbProfile; "<friendlyurls>"; "</")="yes"; "!"; "?");

mn:=@Explode("01 02 03 04 05 06 07 08 09 10 11 12"; " ");
md:=@Explode("January February March April May June July August September October November December"; " ");
dt:=@ReplaceSubstring(@Right(a; 2); mn; md)+" "+@Left(a; 4);

b:="<div id=\"archives\">";
c:="<h4>Monthly archive</h4>";
d:="<ul>";
e:="<li><a href=\""+DbPath+"bymonth"+qm+"OpenView&Count=-1&RestrictToCategory="+a+"\">"+dt+"</a></li>";
y:="</ul>";
z:="</div>";

@Implode(b:c:d:e:y:z; @NewLine)

XSLT

For the Ajax version, I am doing the same with XSLT: /domino/bymonth is the view I am transforming, and this is the XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:template match="/">
<h4>Archive</h4>
<ul>
<xsl:apply-templates select="//viewentry"/>
</ul>
</xsl:template>
<xsl:template match="viewentry">
<xsl:variable name="month"><xsl:value-of select="normalize-
space(substring-after(.,'-'))"/></xsl:variable>
<li><a href="#month-{normalize-space(.)}" onclick="G.app.month(this)">
<xsl:choose>
<xsl:when test="$month='01'">January</xsl:when>
<xsl:when test="$month='02'">February</xsl:when>
<xsl:when test="$month='03'">March</xsl:when>
<xsl:when test="$month='04'">April</xsl:when>
<xsl:when test="$month='05'">May</xsl:when>
<xsl:when test="$month='06'">June</xsl:when>
<xsl:when test="$month='07'">July</xsl:when>
<xsl:when test="$month='08'">August</xsl:when>
<xsl:when test="$month='09'">September</xsl:when>
<xsl:when test="$month='10'">October</xsl:when>
<xsl:when test="$month='11'">November</xsl:when>
<xsl:when test="$month='12'">December</xsl:when>
<xsl:otherwise>Incorrect: <xsl:value-of select="$month"/></xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of select="substring-before(.,'-')"/>
</a> (<xsl:value-of select="@children"/>)</li>
</xsl:template>
<xsl:template match="*"><xsl:copy-of select="."/></xsl:template>
</xsl:stylesheet>

JavaScript

And just for the fun of it, here's how it could be done in JavaScript using the library described in my previous post.

G.date={
mm:'January February March April May June July August September October November December'.split(' ')
...
}
G.app={
...
archive:function(){
    var m=G.app,v=[],o,x,i,n,nn,t,nx
    v.push('<h4>Archive</h4><ul>')
    o=G.get(m.path+'bymonth?ReadViewEntries&CollapseView&'+G.time())
    x=$$('viewentry',o)
    for(i=0;i<x.length;i++){
        n=$$('text',x[i])[0].firstChild.nodeValue
        nx=n.split('-')
        nn=x[i].getAttribute('children')
        t=G.date.mm[nx[1]-1]+' '+nx[0]
        v.push('<li><a href="#month-'+n+'" onclick="G.app.month(this)">'+t+'</a> ('+nn+')</li>')
    }
    v.push('</ul>')
    G.put('archive',v)
}
}

Star rating

0%

Comments

To add a comment, log in or register as new user. It's free and safe.