So, as I reported recently I’ve been working on an internal blog to report the clever stuff we do in the IT shared service line within the corporate where I work. The reason behind doing it is of course to raise awareness of the great stuff I see the broader team delivering each week. This might be grass roots incremental or possibly (hopefully!) ground breaking and disruptive.
Now I’m getting blog postings, I’ve managed to deliver a KPI on the Sharepoint list hosting the blog, I’ve worked through how to create a chart to make progress through the year obvious, but now I want to get a summary of the blog postings on pages elsewhere in the Sharepoint server.
Unfortunately, while I have a large team of developers, the reality is they’re all fully busy so I’ve had to work through this problem myself.
Here’s some guidance for others doing the same. First off quick note to say I was surprised at how hard it was. Still, I’ve got there.
So, to get the blog posts and re-display them elsewhere I used Sharepoint Designer. This gives you the ability to place a DataView in a webpart on any page. It turns out the DataView is the Swiss Army knife of Sharepoint programming (at least when you’re using Sharepoint Designer). This control allows you perform an XSL transform on a data source and display the results. The query is represented using CAML and the best reference to help me with my problem was a posting on the Sharepoint Designer blog. Look for the entry on the CAML query. My select command turned out like this:
selectcommand="<View><Query><OrderBy><FieldRef Name='PublishedDate' Ascending='FALSE'/></OrderBy><Where><Geq><FieldRef Name='PublishedDate'/><Value Type='DateTime'><Today OffsetDays='-30'/></Value></Geq></Where></Query></View>"
The next problem is formatting the output. If you don’t format the output you’ll get HTML tags that will disrupt the rest of the page.
So, in the end I did something like the following. Note that I used some XSL to remove the markup where it occurred. I got that from http://blogs.pointbridge.com/Blogs/morse_matt/Pages/Post.aspx?_ID=37.
1: <xsl:template name="RemoveHtmlTags">
2: <xsl:param name="html"/>
3: <xsl:choose>
4: <xsl:when test="contains($html, '<')">
5: <xsl:value-of select="substring-before($html, '<')"/>
6: <!-- Recurse through HTML -->
7: <xsl:call-template name="RemoveHtmlTags">
8: <xsl:with-param name="html" select="substring-after($html, '>')"/>
9: </xsl:call-template>
10: </xsl:when>
11: <xsl:otherwise>
12: <xsl:value-of select="$html"/>
13: </xsl:otherwise>
14: </xsl:choose>
15: </xsl:template>
16:
17: <xsl:template name="dvt_1.rowview">
18: <xsl:variable name="pureTextBody">
19: <xsl:call-template name="RemoveHtmlTags">
20: <xsl:with-param name="html" select="substring(@Body,0,250)" />
21: </xsl:call-template>
22: </xsl:variable>
23:
24: <tr>
25: <xsl:if test="position() mod 2 = 1">
26: <xsl:attribute name="class">ms-alternating</xsl:attribute>
27: </xsl:if>
28: <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
29: <td class="ms-vb" width="1%" nowrap="nowrap">
30: <span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
31: </td>
32: </xsl:if>
33: <td class="ms-vb">
34: <a href="/CleverStuff/Lists/Posts/Post.aspx?ID={@ID}"><xsl:value-of select="@Title"/></a>
35: </td>
36: <td class="ms-vb">
37: <xsl:value-of select="ddwrt:FormatDate(string(@PublishedDate), 1033, 5)"/>
38: </td>
39: <td class="ms-vb">
40: <xsl:value-of select="$pureTextBody" disable-output-escaping="yes" /></td></tr>
41: </xsl:template>
42: l:stylesheet>
Now, I still have a problem. I’m getting an error message at the bottom of the (successfully) displayed list. The message is “An error occurred processing the data view. The XslText property is empty.”. Any ideas???? This Microsoft KB article has some information but it’s for Sharepoint 2003. I might have to get one of the dev team onto it:)
Update: 16 July
Doh! Figured the problem out - I had an extra DataView webpartzone inserted. I think this is an outcome of the sluggish performance of Sharepoint Designer. You tend to click too many times when you're inserting controls...