This project is read-only.

Display Values From Database

XsltDb provides mdo:sql extension that allows you read and write data from/to database.

The followng sample loads and display list of modules installed into your DotNetNuke instance:

  <xsl:for-each select="mdo:sql('SELECT * FROM dnn_DesktopModules', 'mod')//mod">
As you see "dnn_" prefix is hardcoded in SQL query so the code above is not portable. On another DNN instance it can cause error. We can use {databaseOwner} and {objectQualifier} meta tags to build more portable queries.
Another issue here is that we select all fields (*) but use only one (FriendlyName). So it is better to use exact list of columns. In some cases it can be significant performance issue.

The folowing sample is more accurate:

<!-- SQL query definition. As you see DNN meta tags are used to build right object names.-->
<xsl:variable name="sql">
   SELECT FriendlyName, Description
   FROM {databaseOwner}[{objectQualifier}DesktopModules];

<!-- Execute query and build XML naming each row as "module" -->
<xsl:variable name="modules" select="mdo:sql($sql, 'mod')"/>

<table border="1">
  <tr><td>Friendly Name</td><td>Module Description</td></tr>
  <!-- enumerate modules and build a 2-column table -->
  <xsl:for-each select="$modules//mod">
You may want to review XML that mdo:sql returns. Do it as follows:

<!-- Full form -->
  select="mdo:html(mdo:sql('SELECT top 2 * FROM {databaseOwner}[{objectQualifier}DesktopModules]', 'mod'))"

<!--  Short form {h{...}}, that is equivalent of the full form -->
{h{mdo:html(mdo:sql('SELECT top 2 * FROM {databaseOwner}[{objectQualifier}DesktopModules]', 'mod'))}}

The result will be as follows:

    <FriendlyName>Users And Roles</FriendlyName> 
       Administrators can manage the security roles defined for their portal.
       The module allows you to add new security roles, modify existing security roles,
       delete security roles, and manage the users assigned to security roles.
    <BusinessControllerClass /> 
       Administrators can manage the Tabs within the portal. This module allows you to create a new tab,
       modify an existing tab, delete tabs, change the tab order, and change the hierarchical tab level.
    <BusinessControllerClass /> 

Last edited Jan 30, 2011 at 3:51 PM by findy, version 2


No comments yet.