Solution of Kinds: XML + XSL (in a domino page) -> HTML

If you’ve suffered the insanity of client side xml transformations using Microsoft.XMLDOM and some javascript along the lines of:

loadXML(document.all.item(“pageHeader”).innerHTML, “./ssEmpDetails.xsl”, “pageHeader”);

or some such and would prefer to do the tranform on the server this may be of interest.

The main stumbling block for me was that our xsl pages are stored in Domino pages. The method above lets you point to a URL, notes doesn’t so I’ve written the following function to get the page text from my xsl so that it can be passed to the NotesXSLTransformer.Transform method (which doesn’t appear in my help???).

The function is:

Function getPageText(db As NotesDatabase, pageName As String) As String

'Gets a notes page design element and returns the text of the page. Designed for apps where XSLT info is stored in a page.

Dim nCol As NotesNoteCollection

Dim doc As NotesDocument

Dim title As NotesItem, body As NotesItem

Dim noteID As String

'Build a NotesNoteCollection of all page design elements in the database

Set nCol=db.CreateNoteCollection(False)

nCol.SelectPages=True

Call nCol.BuildCollection

'Find page that corresponds to pagename

noteID=nCol.getFirstNoteID

Do Until noteID=""

	Set doc=db.GetDocumentByID(noteID)

	Set title=doc.GetFirstItem("$TITLE")

	Set body=doc.GetFirstItem("$Body")

	

	If title.Text=pageName Then

		getPageText=body.Text

		Exit Function

	End If		

	noteID=nCol.GetNextNoteId(noteID)

Loop	



getPageText=""

End Function

Following is a sample of an agent that takes XML and uses the function to get the XSL and sends the output to the browser:

Sub Initialize

On Error Goto errHandler	

Dim s As New NotesSession



Dim xmlTr As NotesXSLTransformer

Set xmlTr=s.CreateXSLTransformer



' In this case rawXML is a constant defined in the Declarations section.



Print xmlTr.Transform(rawXML, getPageText(s.CurrentDatabase, "ssRoster.xsl"))



Exit Sub

errHandler:

Print Err & ": " & Error

Resume Next

End Sub

If you put the getPageText function in a script library you’ll obviously need to include it in the ‘Options’.

FINALLY, if you’re existing XSLs use the IE5 namespace change them over to the proper one. Dopey here wasted much time figuring that one out.

This will look like pretty simple stuff to the gurus out there, but I spent heaps of time getting it working for us and messing around with NotesStreams I didn’t need in the end - so hopefully this will save someone else some time.

Subject: Solution of Kinds: XML + XSL (in a domino page) → HTML

Note that if you use client-side transforms, you are getting SUBSTANTIALLY more efficiency out of your design. With a good cache design, you’re moving less data across the wire and using less of your server CPU.

That being said, the client-side XML parsers leave a lot to be desired at this point.

Subject: RE: Solution of Kinds: XML + XSL (in a domino page) → HTML

In particular, using IE5.5 I’ve found that just about more of the XSL functionality is not implemented than actually is!

In our case this was the main requirement for trying to do it on the server.

Subject: Solution of Kinds: XML + XSL (in a domino page) → HTML

Nathan is right as usual. Client-side for apps is the way to go in my opinion.

As for XSL transformations, start using sarissa. It’s a sourceforge project that gives a common javascript wrapper to native XML APIs from all browsers. So what you get, is client-side xsl transformations that work in IE and Mozilla based browsers (even the Mac!). You don’t have to write all of the logic to check which browser the user is using and then call the appropriate methods, etc. You write your code as if you could care less which browser is used and let sarissa do that for you.

Here’s a link to sarissa:

http://sarissa.sourceforge.net/doc/

I’ve also converted the code for my xml/xslt views and outlines in my Domino Web Tools project at OpenNTF to use sarissa.

Here’s a link to the OpenNTF project:

http://www.openntf.org/Projects/pmt.nsf/ProjectLookup/Domino%20Web%20Tools

And here’s a link to my online demo that uses the project. The code to transform the views and outlines is all client side and works in IE and Mozilla based browsers (Netscape, Firefox, etc.) Even works in the Mac.

http://jackratcliff.com/jratcliff/dwt/dwt-demo.nsf

Subject: RE: Solution of Kinds: XML + XSL (in a domino page) → HTML

I may be missing something but it would appear that if Sarissa is just a scripting wrapper it doesn’t actually remove the limitations with regards to the actual client XSLT processor.

For example, half of XSLT doesn’t seem to work with IE5. Therefore .xsl’s that work with IE6 and (probably) firefox are broken in IE5/IE5.5.

You may only need one lot of script do do the transorm regardless of browser, but you’ll still need to code multiple stylesheets and probably need additional client script to compensate for anyting you can’t accomplish with a limited XSLT.

This is why in my case I wanted to do the transform on the server - to get hold of a full XSLT implementation.

Subject: RE: Solution of Kinds: XML + XSL (in a domino page) → HTML

You are partly right.

Internet Explorer 6, Netscape 6+, and Mozilla all support the XSLT 1.0 standard.

Whereas IE 5 and 5.5 support an earlier form of the XSLT standard – the XSL Working Draft (or XSL-WD for short).

Therefore, you could write two versions of your XSL to support the new standard and the older draft.

However, the good news is that you do not need to do this. For IE, you can setup a web page to automatically download and install the latest version of MSXML.

About 3 years ago I started setting up my web apps to include a page that will automatically download and install v3 of MSXML. Microsoft has instrusctions on how to do this here:

Here is a good link for you to check out as well:

http://www.bayes.co.uk/xml/index.xml?/xml/utils/instalmsxml.xml

So bottom line is this: You CAN do client-side XSLT in IE5+, Mozilla, Netscape 6+. If, however, you really need to support older browsers or browser that do not yet support XSLT (Opera, Safari,etc.), then you will need to do your transformations server-side. And, if that’s the case I would suggest you look at Cocoon > Apache Cocoon

HTH,

Jack