Home > Domino Tips > Developer > Other > AddParameter to a NotesXSLTransFormer
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

OTHER

AddParameter to a NotesXSLTransFormer


Sean Haggerty
02.09.2005
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Other
Create a dynamic user-driven navigator for a Notes/Domino application
How to apply XSL style sheets to XML views
Comparing replicas on clustered Lotus Domino servers
Creating a Lotus Notes view column categorized by month
Using the XMLHTTP object for integration with Domino or any RDBMS back end
Hiding field properties/data from DocProperties box
Export a view to Excel without coding
Prevent document deletion if there are response documents
Switching between test IDs quickly
Using DXL (Domino XML) to review/modify documents

Lotus Notes Domino Coding and Development
Tutorial: 30 LotusScript tips
A bevy of Notes/Domino development tips
A Formula language for Lotus Notes introduction -- 7 tips in 7 minutes
Top 10 Notes/Domino developer tips of 2006
Sending and logging faxes from Lotus Notes and Domino
Accessing documents in a Lotus Notes database
A smorgasbord of Notes/Domino development tips
Creating a Lotus Notes view column categorized by month
A project-tracking application for Lotus Notes Domino
What the new Office means for developers

LotusScript
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts