Data View Web Part Tricks
One of the most handy out of the box customization components in my opinion is the Data View Web Part, but mucking around in XSLT can be a pain at times so here’s some reference points for making things easier, these work with SharePoint 2007/2010 and anything else that can use XSLT.
The first snippet is for pulling unique values down from your data source initially. The second is the much more fun way to make it so the DVWP filter drop downs are unique per column. The filter drop down unique value code snippet is put in to the template and is field type independent. Next we have an XSLT template for changing a string to be all uppercase to make a query comparison case-insensitive effectively, it can also be used for always showing a field as uppercase.
I also pasted some of my older XSLT tidbits related to truncated strings for Read More links and proper string extraction for rendering url and image fields.
Unique Values in initial query <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[not (@Title=preceding-sibling::Row/@Title)]" /> Unique values in filter drop downs <xsl:when test="starts-with($fieldname, '@')" <xsl:variable name="dvt_Rows"> Changed select from $Rows lt;xsl:for-each select="/dsQueryResponse/Rows/Row[not(@*[name()=$dvt_FieldNameNoAtSign]=preceding-sibling::Row/@*[name()=$dvt_FieldNameNoAtSign])]"> <xsl:sort select="@*[name()=$fieldname]" order="ascending" data-type="{$sorttype}" /> <xsl:copy-of select="." /> <xsl:variable> Case Insensitive Comparison (or change case) <xsl:template name="ToUpper"> <xsl:param name="StringValue"/> <xsl:value-of select="translate($StringValue, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> <xsl:template> Field Length Truncate (Read More link and fitting in long content) <a href="@FileRef”> <xsl:variable name="truncate-length” select="40”/> <xsl:value-of select="substring(@Title,1, $truncate-length)”/> <xsl:if test="string-length(@Title) > $truncate-length”> <xsl:text>... xsl:if> </a> Properly format a URL or image field Link: <a href="{substring-before(@URL, ', ')}"> <xsl:value-of select="substring-after(@URL, ', ')"/> </a> Image: <img src="{substring-before(@Field, ', ')}" alt="{substring-after(@Field, ', ')}"/>
Categories: 2007, SharePoint, XSLT
Hi,
I have a basic dvwp with the filters on the column headings. I know how to substring out the html in the AssignedTo (Person column) but can never find the code to fix the filter on the top of the column so it only shows the name of the person and not the html.
Basic filter code is:
@AssignedTo
AssignedTo
Assigned To
text
1
x:integer
Any help for a newbie is appreciated!
Guess it did not want to let me paste code – let’s try this again: (using sharepoint 2007)
@AssignedTo
AssignedTo
AssignedTo
text
1
x:integer
Hi TLunn, I’ve moved my blog (new spot isn’t hosted by wordpress so allows html to be pasted). http://withinsharepoint.com/archives/19
Although, it sounds like you’re trying to type the html out while in the design view rather than the code review? If you type out any html in the design view it gets added as plain text which is rarely what you want 🙂 if you click the table header with both design/code view open you can see where to add your html in the page markup.