ddwrt namespace – extension functions detailed

Webparts like DataFormWebPart are still useful and powerful webparts, even if Microsoft is trying to push the SharePoint development to client side by introducing JSLink. One of the reason is because XSLT is extended to some functions coming from ddwrt namespace. These can be found and documented on this link. I am also extended the page by presenting how actually these functions can be used in your XSLT code.

Function Usage Output
GetFileExtension <xsl:value-of select=”ddwrt:GetFileExtension(‘excelfile.doc’)” /> doc
GetVar and SetVar <xsl:variable name=”MyVar” />
<xsl:value-of select=”ddwrt:SetVar(‘MyVar’,’My Value’)” />
<xsl:value-of select=”ddwrt:GetVar(‘MyVar’)” />
My Value
IsPrivilegedUser <xsl:if test=”ddwrt:IsPrivilegedUser() = false”>Not admin</xsl:if> Not admin
Limit <xsl:value-of select=”ddwrt:Limit(‘Long text’, 4,’…’)” /> Long…
Counter <xsl:value-of select=”ddwrt:Counter()” />,<xsl:value-of select=”ddwrt:Counter()” />,<xsl:value-of select=”ddwrt:Counter()” /> 1,2,3
FormatDate <xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,1)” /><br />
<xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,3)” /><br />
<xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,4)” /><br />
<xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,5)” /><br />
<xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,7)” /><br />
<xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,12)” /><br />
<xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,13)” /><br />
<xsl:value-of select=”ddwrt:FormatDate(‘2014-08-20T08:00:00Z’,1033,15)” />
Wednesday, August 20, 2014
1:00 AM
8/20/2014 1:00 AM
Wednesday, August 20, 2014 1:00 AM
1:00:00 AM
8/20/2014 1:00:00 AM
Wednesday, August 20, 2014 1:00:00 AM
IfNew <xsl:if test=”ddwrt:IfNew(‘2014-08-20T08:00:00Z’) = ‘true'”>Recent</xsl:if>
ListProperty  <xsl:value-of select=”ddwrt:ListProperty(‘itemCount’)” />
<xsl:value-of select=”ddwrt:ListProperty(‘title’)” />
UserLookup <xsl:value-of select=”ddwrt:UserLookup($UserID,’ID’)” />
<xsl:value-of select=”ddwrt:UserLookup($UserID,’Email’)” />
<xsl:value-of select=”ddwrt:UserLookup($UserID,’Login’)” />

I consider these functions very valuable. I personally used with some success GetVar and SetVar for making more complicated calculation in the webpart without being forced to call XSLT templates recursively. So, if you still develop in XSLT, which is not a bad idea, you can look if you can use these functions. . If you can see this attribute, xmlns:ddwrt=http://schemas.microsoft.com/WebParts/v2/DataView/runtime, this means you can use them.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s