Aug
27
Posted by:
Stefan Cullmann
8/27/2008
If you read my last blog [Token] based module templates and XSL compared, you might have asked yourself why I transformed the data into XML as the Announcement module doesn’t offer any XML feed beside the default RSS feed.
I needed a simple example, and a lot of users are already familiar with the Token based approach of the Announcement module.
In contrast, the User Defined Table (UDT) uses XSL-transformations for templating. I will repeat yesterday's example covering now the UDT module.
Puppies Reloaded
After a UDT is placed on a page, columns need to be added. Each column has a title and a data type. The data type provides the suited editor, rendering and other optional features.
Afterwards the table is ready to get filled with data.
By default, the data gets displayed as simple table grid.
As already mentioned, UDT allows also XSL based rendering. Let’s have a look at the XML presentation of this example:
<UserDefinedTable xmlns="DotNetNuke/UserDefinedTable">
<Data>
<UserDefinedRowId>1</UserDefinedRowId>
<Title>Puppy Kinda</Title>
<Description>For pubs between 8 weeks and 6 months of age</Description>
<URL><!--http://www.server.com/PuppyKinda--><a href="/dnn490/LinkClick.aspx?link=http%3a%2f%2fwww.server.com%2fPuppyKinda&tabid=54&mid=370" target="_blank">http://www.server.com/PuppyKinda</a></URL>
<EditLink>http://localhost/dnn490/Puppies/tabid/54/ctl/edit/mid/370/UserDefinedRowId/1/Default.aspx</EditLink>
<URL_UDT_Original>http://www.server.com/PuppyKinda</URL_UDT_Original>
</Data>
<Data>
<UserDefinedRowId>2</UserDefinedRowId>
<Title>Primary Paws</Title>
<Description>For Puppy Kinda graduates and young dogs from 4 months age</Description>
<URL><!--http://www.server.com/PrimaryPaws--><a href="/dnn490/LinkClick.aspx?link=http%3a%2f%2fwww.server.com%2fPrimaryPaws&tabid=54&mid=370" target="_blank">http://www.server.com/PrimaryPaws</a></URL>
<EditLink>http://localhost/dnn490/Puppies/tabid/54/ctl/edit/mid/370/UserDefinedRowId/2/Default.aspx</EditLink>
<URL_UDT_Original>http://www.server.com/PrimaryPaws</URL_UDT_Original>
</Data>
<Data>
<UserDefinedRowId>3</UserDefinedRowId>
<Title>Master Paws</Title>
<Description>An agility based program for dogs over one year old</Description>
<URL><!--http://www.server.com/MasterPaws--><a href="/dnn490/LinkClick.aspx?link=http%3a%2f%2fwww.server.com%2fMasterPaws&tabid=54&mid=370" target="_blank">http://www.server.com/MasterPaws</a></URL>
<EditLink>http://localhost/dnn490/Puppies/tabid/54/ctl/edit/mid/370/UserDefinedRowId/3/Default.aspx</EditLink>
<URL_UDT_Original>http://www.server.com/MasterPaws</URL_UDT_Original>
</Data>
<Fields>
<FieldTitle>Title</FieldTitle>
<Required>false</Required>
<FieldOrder>0</FieldOrder>
<FieldType>String</FieldType>
</Fields>
<Fields>
<FieldTitle>Description</FieldTitle>
<Required>false</Required>
<FieldOrder>1</FieldOrder>
<FieldType>String</FieldType>
</Fields>
<Fields>
<FieldTitle>URL</FieldTitle>
<Required>false</Required>
<FieldOrder>2</FieldOrder>
<FieldType>URL</FieldType>
</Fields>
<Context>
<ModuleId>370</ModuleId>
<TabId>54</TabId>
<PortalId>0</PortalId>
<UserName>host</UserName>
<DisplayName>SuperUser Account</DisplayName>
<ApplicationPath>/dnn490</ApplicationPath>
<HomePath>/dnn490/Portals/0/</HomePath>
<LocalizedDate>8/28/2008 5:11 AM</LocalizedDate>
<Now>2008-08-28T05:11:51.41+02:00</Now>
</Context>
</UserDefinedTable>
(this is only an extract, it is already shortened to get a better impression!)
Features of UDT's XML
The XML consists out of three parts: one section containing the data, a second part contains the column field settings. The third part, Context, offers additional information that might be helpfull during rendering.
You might have already noticed that the "URL" element doesn't simply contain the url we entered. It fact it contains the complete html needed for a link. This element is used directly for the grid view. The original URL isn't lost, it is inside the element URL_UDT_Original. UDT has a lot of these "hidden columns", they are reuired for rendering, calculating and filtering.
One really major different is the declaration (xmlns="DotNetNuke/UserDefinedTable") of a default namespace in the first line. Each element (and attribute if present) belongs to the namesspace DotNetNuke/UserDefinedTable and can't be ignored, particualry with regard to XSL stylesheets.
XSL Stylesheet for the UserDefinedTable
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:udt="DotNetNuke/UserDefinedTable">
<xsl:output method="xml" indent="yes" omit-xml-declaration ="yes"/>
<xsl:template match="udt:UserDefinedTable">
<table>
<xsl:for-each select ="udt:Data">
<tr>
<td>
<b><xsl:value-of select ="udt:Title"/> </b> -
<xsl:value-of select ="udt:Description"/> 
<i><a href="{udt:URL_UDT_Original}">Read more..</a></i>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
This is nearly the same XSL as yesterday. Inside the stylesheet declaration the namespace "DotNetNuke/UserDefinedTable" gets accessible throught the prefix udt.Each time the stylesheet addresses an UDT element, "udt:" needs to be added as prefix.
Conclusion
Writing an XSL stylesheet for the User Defined Table isn't much difficult. It takes a bit more time to pick up the relevant elements out of the XML, and we need to take care on the namespace.
In my next blog I will cover the Token2XSL-Editor, which is part of UDT since 3.4.0.