|
|
|
|
|
|
|
|
|
|
Parsing XML with LotusScript and Microsoft's XML object (continued)
The second XMLStyleSheet agent XSL style sheets are really a subject by themselves but, as always, you can start with something simple. A good starting point is using HTML elements with XSL statements to select fields from a source XML document. An analogy would be a mail merge.
For this agent, I created a new TableTest document to hold the style sheet and used it against the XML field in my News document which was populated when I ran the XMLHeadlines agent above. Using existing XML data from this field allowed me to try out the loadXML function which loads a string rather than a file. With the XML and style sheet data loaded into two separate objects, it was a simple matter of calling transformNode() and putting the returned string of HTML in a new document. Below is the style sheet I used in the agent.
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD><H3><xsl:value-of select="rdf:RDF/channel/title"/></H3></TD>
</TR>
<xsl:for-each select="rdf:RDF/item">
<TR>
<TD><xsl:value-of select="title"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
|
The "template match" line says to start at the root of the XML document. The "value-of select" statement picks up a particular field value as in the first agent (in this case, the title of the channel). The "for-each" statement repeats a block of HTML for each matching element (in this case, each item). Within the block I get the particular title value. The following is a partial output:
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD><H3>DominoPower News Center</H3></TD>
</TR>
<TR>
<TD>Battle against piracy</TD>
</TR>
<TR>
<TD>SmartSuite review</TD>
</TR>
|
The beauty of this approach is that you can use the same agent with different style sheets, depending on what you want as output, a bit like using sub-forms in a form. The style sheets can be very complex and perform selection, ordering, pattern matching, and can have embedded JavaScript in as well. Hopefully this little example will whet your appetite for further experimentation as it did mine.
Mark Lawson is a freelance Notes consultant in the UK. He can be reached at markl@electricmemo.com.
[ Prev ]
|
|
|
|
|
|
-- Advertisement --
2-Minute Tutorials
How do I...
- integrate MS Office or OpenOffice with Notes?
- create cross-tab reports and charts?
- print serial letters and mailing labels?
- create PDFs in Lotus Notes?
Check out the 2-minute tutorials here. |
-- Advertisement --
Now for the first time, real-time dashboards within Notes!
No more tedious report iteration and endless data exporting! The New IntelliPRINT Dashboard Reporting now empowers you to easily create analyzable widgets and real-time dashboard reports. Your business managers can then quickly customize, extend, and analyze these dashboards to their heart's content!
All from within your Lotus Notes data, all in real-time!
Download your Free Trial today! |
|
|
|
|
|
|
|
|