PermaLinkXML View transformation 101.04/05/2004
Written By : Peter de WaardCategory : XML
Location : Freiburg, Germany
When looking at ways to extend Domino, one of the first candidates are views. Lotus offers a standardized, no programming, way to extract XML from views using ?ReadViewEntries. When upgrading Notes Client applications to Domino reading your views this way, saves you from recoding the views to be web compliant. The pattern is simple: Use something (a servlet, an agent, a ASP/JSP/PHP page) to read the Domino XML, load an XSLT stylesheet and transform the XML to something displayable: (x)HTML, WML etc.
To do this succesfully, you need to add XLST to the languages you speak. When you liked set theory at school, you will like it, if you are a die-hard procedural coder, it will add another item on your daily curse list. I have compiled some examples, that show some basics how to translate the format ?ReadViewEntries is producing. I will release the example over time in my column here. Using this techniques you can reduce the number of views you need in a Domino database and keep the indexer from beeing too busy.
To understand the examples you need to have some basic understanding of XSLT. You might want to visit the W3Schools XSLT tutorial before. In a nutshell: the XML elements are parsed by the XSLT processor starting from the XML root and matched against rules in the XSLT file. There you coded templates with a match condition. The conditions are written in XPath. XPath is easy to get started with and incredible complex to master. Michael Kay's excellent XSLT Programmer's Reference has more than 1000 pages.
When looking at ?ReadViewEntries we see XML that looks like this:
<viewentries toplevelentries="2">
<viewentry position="1" unid="3549DC90FB00BE0948256E6C00379E4A" noteid="8F6" siblings="2">
<entrydata columnnumber="0" name="Priority">
<text>High</text>
</entrydata>

<entrydata columnnumber="1" name="DueDate">
<datetime>20040404</datetime>
</entrydata>

<entrydata columnnumber="2" name="DueTime">
<datetime>T181500,00</datetime>
</entrydata>

<entrydata columnnumber="3" name="Approver">
<text>CN=Stephan H. Wissel/O=4friends</text>
</entrydata>

<entrydata columnnumber="4" name="Sequence">
<number>1</number>
</entrydata>

<entrydata columnnumber="5" name="Colors">
<textlist>
<text>red</text>

<text>blue</text>

<text>green</text>
</textlist>
</entrydata>

<entrydata columnnumber="6" name="LuckyNumbers">
<numberlist>
<number>1</number>

<number>2</number>

<number>3</number>
</numberlist>
</entrydata>

<entrydata columnnumber="7" name="MileStoneDates">
<datetimelist>
<datetime>20040403</datetime>

<datetime>20040404</datetime>

<datetime>20040405</datetime>
</datetimelist>
</entrydata>

<entrydata columnnumber="8" name="Reviewers">
<textlist>
<text>CN=Pitt de Waard/O=BFS/C=DE</text>

<text>CN=Nigel Choh/OU=tao/O=4friends</text>
</textlist>
</entrydata>
</viewentry>

<viewentry position="2" unid="392F36402596284B48256E6C0037C76C" noteid="8FA" siblings="2">
<entrydata columnnumber="0" name="Priority">
<text>High</text>
</entrydata>

<entrydata columnnumber="1" name="DueDate">
<datetime>20040404</datetime>
</entrydata>

<entrydata columnnumber="2" name="DueTime">
<datetime>T210900,00</datetime>
</entrydata>

<entrydata columnnumber="3" name="Approver">
<text>CN=Pierre Kerchner/O=4friends</text>
</entrydata>

<entrydata columnnumber="4" name="Sequence">
<number>33</number>
</entrydata>

<entrydata columnnumber="5" name="Colors">
<textlist>
<text>red</text>

<text>white</text>

<text>blue</text>
</textlist>
</entrydata>

<entrydata columnnumber="6" name="LuckyNumbers">
<numberlist>
<number>4</number>

<number>5</number>

<number>6</number>

<number>8</number>
</numberlist>
</entrydata>

<entrydata columnnumber="7" name="MileStoneDates">
<datetimelist>
<datetime>20040403</datetime>

<datetime>20040404</datetime>

<datetime>20040405</datetime>
</datetimelist>
</entrydata>

<entrydata columnnumber="8" name="Reviewers">
<textlist>
<text>CN=Stephan H. Wissel/O=4friends</text>

<text>CN=Cheong Choi Fong/O=4friends</text>
</textlist>
</entrydata>
</viewentry>
</viewentries>

So the elements we have to deal with are: viewentries, viewentry, entrydata, text, datetime, number, textlist, datetimelist and numberlist. One interesting aspect here: we are only dealing with 3 datatypes as single or multi-value. No special treatment of keywords, name or author fields.

The sequence of rules in the XSLT file doesn't matter, however the rule priority. Rule priorities might sound a bit odd, however we deal with them in real live every day, an example: When you approach an intersection you have to give way to cars coming from the right road (the basic rule) unless there is a traffic sign that gives you priority (priority 2) unless there is a traffic light that shows red (priority 3) unless a traffic police officer signals you to go ahead (priority 4 - the highest wins). These 4 rules are independent, however when more than one of the rules is present, there is a clear priority. In XPath the rule follows the priciple: the closer the match, the higher the priority. The XPath expression * (= Anything) thus has the lowest priority.
Our template looks like this:
<xsl:stylesheet version="1.0">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
<!-- Here is the basic html template for the output html file -->

<html>
<head>
<title>View rendering example</title>

<link rel="stylesheet" media="display" type="text/css" href="BVTscreen.css"/>
</head>

<body> This is an example how to render a Domino XML View into a HTML document containing a table. The example will work with any flat Domino view.
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="viewentries">
<div id="documentbody"> This view contains
<xsl:value-of select="@toplevelentries"/>
documents.
<table id="viewcontent">
<thead>
<xsl:apply-templates mode="header"/>
</thead>

<tbody>
<xsl:apply-templates/>
</tbody>
</table>
</div>
</xsl:template>

<xsl:template match="viewentry">
<!--Each viewentry translates to a row in the table -->

<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>

<xsl:template match="entrydata">
<!-- each entry data is a column in the table -->

<td>
<xsl:apply-templates/>
</td>
</xsl:template>

<!-- Here are the 3 data types in single value, number and date time are just copied, would need some facelift -->

<xsl:template match="text">
<!--copy the column value -->

<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="number">
<!--copy the column value -->

<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="datetime">
<!--copy the column value -->

<xsl:value-of select="."/>
</xsl:template>

<!-- the 3 list types -->

<xsl:template match="textlist">
<!--display as ordered list -->

<ol>
<xsl:apply-templates/>
</ol>
</xsl:template>

<xsl:template match="numberlist">
<!--display as unordered list -->

<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>

<xsl:template match="datetimelist">
<!--display as unordered list -->

<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>

<!-- Here are the 3 data types in multi value, number and date time are just copied, would need some facelift -->

<xsl:template match="textlist/text">
<!--copy the column value -->

<li>
<xsl:value-of select="."/>
</li>
</xsl:template>

<xsl:template match="numberlist/number">
<!--copy the column value -->

<li>
<xsl:value-of select="."/>
</li>
</xsl:template>

<xsl:template match="datetimelist/datetime">
<!--copy the column value -->

<li>
<xsl:value-of select="."/>
</li>
</xsl:template>

<!-- Here are the templates to create the table header -->

<xsl:template match="viewentry[position()=1]" mode="header">
<tr>
<xsl:apply-templates mode="header"/>
</tr>
</xsl:template>

<xsl:template match="entrydata" mode="header">
<th>
<xsl:value-of select="@name"/>
</th>
</xsl:template>

<!-- With the following statement we make sure, that NO unwanted elements are copied into the output -->

<xsl:template match="*" mode="header"/>

<xsl:template match="*"/>
</xsl:stylesheet>

The stylesheet is designed for flat views only (no categories). Try it on your own Notes views and let me know how it worked for you.

Commentsv

No documents found

Enter Comments^



Email addresses provided are not made available on this site.





You can use UUB Code in your posts.

[b]bold[/b]  [i]italic[/i]  [u]underline[/u]  [s]strikethrough[/s]

URL's will be automatically converted to Links


:angry: :grin: :cool: :rolleyes: :laugh: :lips: :-o :-p :-( :-D :huh: :emb: :-x :-) :-\ ;-) :cry:






Remember me    

Site purpose and disclaimer
You consider to extend or replace your Domino infrastructure. You found a lot of information about messaging migration. You didn't find much about the applications, other than tool vendors advertisements. You realized that Domino migration is an emotional mine field. Bookmark this site, we will provide information and discuss the move from Domino to J2EE and other environments (both retaining and replacing Domino). We focus on applications, not on messaging.

The articles on this site mention products and phrases, that might be subject to copyright or trademarks. So we acknowledge, that the copyrights belong to the owner of the respective copyright or trademark.The links on this page are provided for convenience and are constitute no endorsement of the content of the target site.

So once your ready to discuss if and/or how to move away from Domino contact us.
Search
Site Contributors
Related Links
Resources
Some of the articles come with sample code or documents. You can get them in the Downloads section. Please check for the copyright accompanying the files.
Unless mentioned otherwise copyright of all of this site content is subject to a creative commons licence.
By Category
Lotus Domino ND7 RSS News Feed RSS Validator OpenNTF BlogSphere
Monthly Archive
Ads by Google