Manage Learn to apply best practices and optimize your operations.

AddParameter to a NotesXSLTransFormer

While transforming Notes documents using DXL I needed to add a parameter to the Stylesheet and AddParameter documentation in R6 was non-existent. Here's how it works...

While transforming Notes documents using DXL, and an XSLT stream pulled in from a Page in a database, I needed to add a parameter to the Stylesheet and AddParameter documentation in R6 was non-existent. Here's how it works:

To add information from outside of the NotesXSLTransformer Object, (that's information available to the agent), you can add values to the transformer using:

Dim transformer As NotesXSLTransformer
Set transformer=session.CreateXSLTransformer
Call transformer.AddParameter("globalparameter" , "God")

To reference that parameter in the Stylesheet, after it has been added to the Transformer, use this XSLT:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="" 
xmlns:dxl="" version="1.0"> <xsl:output 
method="text"/> <xsl:param name="globalparameter"/> <xsl:template 
match="/*"> <xsl:apply-templates 
<xsl:with-param name="globalparameter" select="$globalparameter"/> 
</xsl:apply-templates> </xsl:template>

<xsl:param name="globalparameter"/>
<xsl:for-each select="descendant::dxl:text"> 
<xsl:text/><xsl:value-of select="$globalparameter"/><xsl:value-
of select="normalize-space(.)"/>;<xsl:text/>


The XSLT, in my case, was put on a page called "readers.xsl." Although I didn't call the page from the browser, as an XSLT using its URL, I changed the Page Properties box (Alt+Enter) >> Web Access (part of the first Tab), and set the values to "Other: text/xsl."

How I got LotusScript to pull the XSLT off the page and how I got the readers fields off a Domino document is listed below for those of you who might want to see the whole enchilada.

P.S. I left the rem'd out lines so you can un-rem them and see what output you get when running the agent with Debug LotusScript ON.

Sub Initialize
On Error Goto InitializeError
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Set s = session
s.ConvertMIME = False 
' Do not convert MIME to
 rich text session.ConvertMIME = 
False ' Do not convert MIME 
to rich text REM Open xml 
Dim xml As NotesStream 
Set xml = session.CreateStream 
Call xml.Truncate REM Open xslt Dim xslt As 
NotesStream Set xslt = 
session.CreateStream Call xslt.
Truncate REM Open output 
Dim xmlout As NotesStream 
Set xmlout = session.CreateStream Call xmlout.Truncate

REM Create note collection and 
use a selectionFormula to get the Page that has 
the xslt on it Dim nc As 
NotesNoteCollection Set nc = db.CreateNoteCollection
(True) 'False) 
' Call nc.SelectAllAdminNotes(False) ' Call 
' Call nc.SelectAllDataNotes(False) 
' Call 
' Call nc.SelectAllFormatElements(False) ' 
Call nc.SelectAllIndexElements(False) 
' Call nc.SelectAllNotes(False) ' 
' nc.SelectForms=False ' nc.SelectFrameSets=False ' 
' nc.SelectJavaResources=False ' 
' nc.SelectPages=True ' 
' nc.SelectSubforms=False
nc.SelectionFormula = 
{@Contains($Title;"readers.xsl")} Call nc.BuildCollection

REM Modify the collection - 
take out test documents 
Dim doc As notesdocument 
nid = nc.GetFirstNoteId For i = 
1 To nc.Count Set doc = db.GetDocumentByID(nid) 
nid = nc.GetNextNoteId(nid) Next

REM Open file to hold some 
NotesStream data Dim stream 
As NotesStream Set 
stream = session.CreateStream 
filename$ = "c:docsxml.xml"
If Not stream.Open(filename$)
Messagebox "Cannot open "
 & filename$,, "Error"
Exit Sub
End If
Call stream.Truncate

REM Get the contents of a Page 
Object for the Stylesheet XSL Dim body As 
NotesRichTextItem Set body = 
doc.GetFirstItem("$Body") Call xslt.WriteText
(body.text) ' Call xslt.Close

REM Create Transformer once set, 
style and out Dim transformer As 
Set transformer=session.CreateXSLTransformer
Call transformer.SetStylesheet(xslt)
Call transformer.SetOutput(xmlout)
Call transformer.
AddParameter("globalparameter" , "God")


REM Use Page Stream in Transformer
REM Export Orgs View 
documents as DXL Dim exporter As NotesDXLExporter Dim 
dxlExporter As NotesDXLExporter 
Set dxlExporter = session.CreateDXLExporter 
Call dxlExporter.SetOutput(xml)

Dim vc As NotesViewEntryCollection
Dim vcDoc As NotesDocument
Set view = db.GetView("Orgs")
Set vc = view.AllEntries
For x=2 To vc.Count
Set vcDoc = vc.GetNthEntry(x).document
Call dxlExporter.SetInput(vcDoc)
Call dxlExporter.Process
Print transformer.Transform(xml ) ', xslt ) 
' Print "============"
' Print xml.ReadText()
' Call transformer.SetInput(xml)
' Call transformer.Process
' Print vcDoc.UniversalID
' Print xmlout.ReadText()
' Print "==================="

Call xml.Truncate
Call stream.Close

Exit Sub
Print transformer.log
Print ( "InitializeError: Got error " 
& Error$ & " on line " & Cstr(Erl) & "; 
Error" & Str(Err) & " 
:InitializeError") Resume Next End Sub

The uneventful Output is:

CN=Sean S Haggerty/OU=SoCal/O=My 

And the DXL for the Notes Document was:

<item name='readersPoster' names='true' 
CN=Sean S Haggerty/OU=SoCal/O=My 

Do you have comments on this tip? Let us know.

This tip was submitted to the tip exchange by member Sean Haggerty. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Dig Deeper on Lotus Notes Domino Coding and Development



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury