About This Code
Brief Description:
Converting Domino view XML to hierarchical style
Contributor:
Darina Sadovska
Notes Version:
R6.x, R5.x, R7.x
Last Modified:
10 Dec 2008
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
The view XML you get using ?ReadViewEntries is descriptive. The tree structure of view categories is maintained via position attribute, not via XML structure.
I needed a view XML with tree structure to display a categorized Notes view in TreeView component in .NET. This is the XSLT that can do the trick.
Simply transform your view XML with this XSLT, and you get a hierarchical XML. The first column value in the view entry is loaded into a "value" attribute, UNID is loaded into "unid" attribute.
Usage / Example
INPUT:
View XML retrieved using ?ReadViewEntries. Regular views only, didn't try it with calendar views.
XSLT TRANSFORMATION:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="Digits" select="1234567890"/>
<xsl:template match="/*">
<notesView>
<xsl:apply-templates select="viewentry[not(contains(@position, '.'))]"/> <!--Apply templates for 1st level viewentries-->
</notesView>
</xsl:template>
<xsl:template match="viewentry">
<xsl:element name="{'entry'}"> <!--Create an element called <category>-->
<xsl:attribute name="{'value'}"> <!--Contents value-->
<xsl:value-of select="entrydata[1]/*[1]"/><!--Put contents of first entrydata node as attribute here-->
</xsl:attribute>
<xsl:copy-of select="@unid"/>
<xsl:copy-of select="node()[not(self::entrydata)]"/> <!--Copy node there, but only categories, not entrydata - those are already copied above-->
<xsl:apply-templates select="../viewentry[starts-with(@position, current()/@position) and
string-length(translate(@position,$Digits,'')) = 1 + string-length(translate(current()/@position,$Digits,''))]">
</xsl:apply-templates> <!--Apply templates for subcategories of this category-->
</xsl:element>
</xsl:template>
</xsl:stylesheet>
EXAMPLE OUTPUT:
<notesView>
<entry value="Apéritif">
<entry value="Anchois au vinaigre" unid="38D11C87C33BD5F8C12572E2003E95CC" />
<entry value="Baie d'Along" unid="736B609E2B5C73FDC125725F002A2B68" />
<entry value="Brochettes de parme et melon" unid="E68B96262CA1B2F8C125733E0027A29F" />
<entry value="Pommes de terre à l'aïoli" unid="4AB40766FEEA325CC125733E0027F92B" />
<entry value="Punch Planteur" unid="12F496C876981202C125733F002501AE" />
<entry value="Tartine à l'avocat" unid="F509F09EC48A3238C12573830033265A" />
</entry>
<entry value="Dessert">
<entry value="Cake au citron" unid="D22F908763B2A0F1C125733E003542C0" />
<entry value="Crèmes brûlées à la framboise" unid="54F74961691F05DEC125733100254C45" />
</entry>
</notesView>
Comments
Posted by ajay x mali on 10/12/2009 08:47:25 AMXML
Hi Darina,
Could you please also add the notes xml view, before applying XSLT TRANSFORMATION.
Thanks !!
Regards
Ajay B Mali