|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Sophisticated Meets Simple For Document Management
Share. Control. Manage.
Documents, emails, and content in the context of how work is done.
Native to Lotus Domino. The User Experience unseen for Lotus Domino.
Do more with less. Really.
See the possibilities Docova unleashes for Lotus Domino. |
-- Advertisement --
Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.
Register by April 10 to save $200. |
|
|
|
|
|
|
|
|
|
|