2 minute read
I’ve always prided myself in building Data View Web Parts (DVWPs) that are bulletproof, meaning they will run and render no matter what. However, I ran into something today which gives me pause.
The setup on this is a little complicated, so bear with me. In SharePoint 2007, if you have a Lookup column which is based on a Single line of text column and that column value contains an ampersand, the ampersand is escaped in the DataSource for your DVWP.
So what does that mouthful actually mean? In this case, I’ve built some custom navigation on the home page of a site which is driven by three lists. Here’s a partial screenshot of the navigation the DVWP generates, obfuscated of course.
How the whole DVWP works is a different topic, but it’s a big hit with the person who manages it and the users love it, too. I did a webinar about how the whole thing works for the USPJ Academy’s SharePointWebinars.com site last month. You can still watch it at DataView Web Part Unlocked.
Here are two screen snippets from an AggregateDataSource in SharePoint Designer 2007.
On the left, you see the Navigation Areas list, which has items for the highest level of the navigation. The one item you see has its Title=”Collaborations & Partners”. On the right, you see one item from the Navigation SubAreas list. The Navigation Area column is a Lookup column into the Title column in Navigation Areas. As you can see, the value which is returned from the DataSource is “Collaborations & Partners”, so the ampersand is escaped.
In upgrading this site to SharePoint 2010, I see something different. Here are snippets from the exact same AggregateDataSource in SharePoint Designer 2010.
Egad. The Lookup column on the right doesn’t have its ampersand escaped! I’ve been very careful in my DVWP to handle the ampersand situation, and I have a template in place in 2007 called FixAmpersands that replaces an ampersand (‘&’) with ‘&’ so that I can do “joins” between the lists in XSL.
<xsl:template name="FixAmpersands"> <xsl:param name="StringValue"/> <xsl:variable name="Ampersand" select="'&'" /> <xsl:choose> <xsl:when test="contains($StringValue, $Ampersand)"> <xsl:value-of select="concat(substring-before($StringValue, $Ampersand), '&amp;', substring-after($StringValue, $Ampersand))"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$StringValue"/> </xsl:otherwise> </xsl:choose> </xsl:template>
So the net-net of this is that it looks like the ampersand is not escaped in SharePoint 2010 DataSources in SharePoint Designer 2010. It’s easy to fix on this case, because I can simply remove the FixAmpersands stuff, since I no longer need it. What concerns me more is that the DataSource seems to have changed from 2007 to 2010. Anyone else seen anything like this?