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="http://www.w3.org/1999/XSL/Transform" 
xmlns:dxl="http://www.lotus.com/dxl" version="1.0"> <xsl:output 
method="text"/> <xsl:param name="globalparameter"/> <xsl:template 
match="/*"> <xsl:apply-templates 
select="dxl:item[@readers='true'&#93;&#91;descendant::dxl:text&#93;
">
<xsl:with-param name="globalparameter" select="$globalparameter"/> 
</xsl:apply-templates> </xsl:template>

<xsl:template 
match="dxl:item&#91;@readers='true'&#93;&#91;descendant::dxl:text&#9
3;">
<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/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

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 
nc.SelectAllCodeElements(False) 
' Call nc.SelectAllDataNotes(False) 
' Call 
nc.SelectAllDesignElements(False) 
' Call nc.SelectAllFormatElements(False) ' 
Call nc.SelectAllIndexElements(False) 
' Call nc.SelectAllNotes(False) ' 
nc.SelectActions=False 
' nc.SelectForms=False ' nc.SelectFrameSets=False ' 
nc.SelectImageResources=False 
' nc.SelectJavaResources=False ' 
nc.SelectMiscFormatElements=False 
' nc.SelectPages=True ' 
nc.SelectStyleSheetResources=False
' 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$)
 Then
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 
NotesXSLTransformer 
Set transformer=session.CreateXSLTransformer
Call transformer.SetStylesheet(xslt)
Call transformer.SetOutput(xmlout)
Call transformer.
AddParameter("globalparameter" , "God")

transformer.InputValidationOption=0

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
Next
Call stream.Close

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

The uneventful Output is:

;&#91;System&#93;;
CN=Sean S Haggerty/OU=SoCal/O=My 
Business;God_C5;God_C2;God_C6;;

And the DXL for the Notes Document was:

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


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

This tip was submitted to the SearchDomino.com 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.

This was first published in February 2005

Dig deeper on Lotus Notes Domino Coding and Development

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close