I’ve been playing with AJAX in several places, making calls to ReadViewEntries to get counts and to do lookups, and finally decided to display an entire view with an AJAX call. Using Sarissa this is very easy, you can even define a stylesheet to translate the view before displaying it to the page, I think this is the way to go.
First include sarissa.js and sarissa_dhtml.js, the second of these contains what we want to use: Sarissa.updateContentFromURI( URL, element, XSLT ). This does all the hard AJAX work for us by creating an xmlhttp object and making a call to the provided URL, it then processes the retrieved XML with the XSL processor you provide and places the results in the element you specify.
To start this off I needed a stylesheet that would transform a ReadViewEntries call into HTML, there’s an awesome example of this in Domino Web Tools, but I was having some issues getting the XSL to load in IE and didn’t have the time to work through the XSL and find the issue. So I kept looking and found a nice simple stylesheet (I can’t remember where I found this, if anyone knows, let me know so I can give proper credit). I made a couple small changes to the stylesheet to fit my needs (added an anchor tag on text items to link to the document).
Time to test out a view, I created a form and wrote up some pass-thru html with an empty div as a placeholder for the view. Added the sarissa.js and sarissa_dhtml.js libraries into the JS Header and added a quick onLoad call:
Sarissa.updateContentFromURI(’/myView?ReadViewEntries&count=30′, document.getElementById(”myPlaceholder”));
That worked fine and got some straight xml placed into the div. Now onto the XSL file to get some html to place in the div. I created a new page and pasted the XSL file into it (remember to change content-type to ‘text/XML’). Now that the XSL file is there, I needed to set up an XSLT processor to pass to Sarissa:
var proc = new XSLTProcessor();
var xslDoc = Sarissa.getDomDocument();
xslDoc.load(”viewentries.xsl”);
proc.importStylesheet(xslDoc);
This creates another AJAX call to load the XSL document and import it into a re-usable XSLT processor.
From here all I need to do is pass the processor to Sarissa and it will take care of all the work.
Sarissa.updateContentFromURI(’/myView?ReadViewEntries&count=30′, document.getElementById(”myPlaceholder”),proc);
Once everything is set to go you can easily create links that just do another Sarissa call to a different view (or same with different parameters), using the same XSLT processor. You can easily have this replace the current view or even display another view in a different div.
Next Time: Displaying Notes Views with AJAX Part 2: Adding Bob Obringer’s Ultimate View Navigator
XSL File Used: viewentries.xsl





Rich,
Did you ever write Part 2 of this article, if so I can’t seem to locate it.
I am very interested in the merger of Bob’s code and yours - would love to see of a demo of the final thing - thanks.
Cheers,
Paul
pconroy
June 20th, 2006
Hi Rich
I tried to implement this and I could only get it to work partially.
I created pages for the sarissa js files and included them.
Using Sarissa without a stylesheet works as expected, the XML is put into the div-tag I specify.
When I create a page containing the stylesheet you supply, I get an error: “Attempt to modify a read-only node”.
I tried to use this code instead:
var proc = new XSLTProcessor();
var xslDoc = Sarissa.getDomDocument(”", “/mydb.nsf/viewgeneric.xsl?openpage”);
proc.importStylesheet(xslDoc);
Sarissa.updateContentFromURI(’/mydb.nsf/myview?readviewentries&count=-1&collapseview’, document.getElementById(”viewbody”), proc);
I then get the error: “The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document”.
What am I doing wrong here?
I am certainly no star when it comes to XSL stylesheets, and I am sure this can be easily resolved.
Eagerly awaiting response.
// Ken
Ken Haggman
August 16th, 2006
Tough to tell, the first place I would look would be the XSL stylesheet, a minor mistake in there will cause the whole thing to not work. When developing XSL I was using Altova XML Spy, I saved a local copy of readviewentries and tested the translation as I went. Altova also has validation built in and will be able to tell you right off the bat if something is wrong with the XSL.
Also one thing to make sure of if your using a page is to make sure you set the content type in page properties to ‘text/xml’.
Hope that helps.
Rich Waters
August 17th, 2006
Hej Rich,
I tries to follow your guidelines but I get an error message: attempt to modify a read only file. Don’t understand where that comes from.
Question: could you send me a sample database so I can work with that as a startingpoint?
Thanks in advance!
// Patrick
quintessens
November 12th, 2006
I’ll see if I can dig up some of that code and toss a sample database together. Almost seems outdated to me at this point
Rich Waters
November 16th, 2006
Hi Rich,
first thanks for this nice text. Clear expleaned, easy to understand.
The only problem i got, was, that the .xsl-file couldn’t be loaded. I found a hint on the Sarissa documentation (http://sarissa.sourceforge.net/doc/index.html), where it says referring to load: “use XMLHttpRequest to load remote documents instead”.
So, if i use:
“var dbPath = window.location.href.substr(0, window.location.href.lastIndexOf(’.nsf’) + 4);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(’GET’, dbPath + ‘/viewentries.xsl’, false);
xmlhttp.send(”);
var xslDoc = xmlhttp.responseXML;”
instead of “xslDoc.load(…)” it works…
This also seems to be the problem in some comments above.
Kind regards,
Stefan
Stefan Deser
March 12th, 2007