Are Ampersands Stored Differently in SharePoint 2010 Than SharePoint 2007?

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.

image

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.

image image

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.

image image

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="'&amp;'" />
  <xsl:choose>
    <xsl:when test="contains($StringValue, $Ampersand)">
      <xsl:value-of select="concat(substring-before($StringValue, $Ampersand), '&amp;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?

Similar Posts

4 Comments

  1. For me, it’s hard to tell whether the change is in the data source itself, or in the method SharePoint uses to retrieve the data (I would opt for the latter).

    Something similar happened to me with XSLT View Web Part vs. Data View Web Part. Compare these two posts:
    – SharePoint 2010, XSLT View Web Part
    http://blog.pathtosharepoint.com/2010/05/28/html-calculated-column-solutions-for-sp-2010-part-ii/
    – SharePoint 2007, Data View Web Part:
    http://blog.pathtosharepoint.com/2009/07/26/html-calculated-column-and-data-view-web-part/

    1. Christophe:

      Your issue in those two posts seems to be just making the data render properly based on how the two types of Web Parts work. In this case, I’m seeing that either a different value is stored in SharePoint 2010, the DataSource delivers a different value to SharePoint Designer 2010, or SPD2010 interprets the value differently. Whichever of these three it is, it seems to be different than how things work in 2007.

      I think I’ll do some more investigation by seeing what value is returned by the Lists Web Service and/or through the Object Model.

      M.

      1. Yes, my issue is to make the data render properly, but it is directly linked to how the data is stored or rendered (my story doesn’t tell what exactly has changed between 2007 and 2010).

        Did you try simply looking at the data source details, in the SPD panel? For my HTML calculated columns, I see a difference, “less than” signs used to be “&lt;” in SP 2007, now they are "<".

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.