If you want to compare two columns, a simple way would be to create a calculated column. However, SharePoint doesn’t let you use Person fields (columns) in calculated column.
With a little XSLT, you can compare two person columns in a DataFormWebPart.
Say you add an extra column to a task list, called “OriginallyAssignedTo” and you want to check if the “AssignedTo” column matches the “OriginallyAssignedTo” column.
Within the DataFormWebPart’s dvt_1 template, you add the following code:
<xsl:variable name="CurrentlyAssignedTo" select="@AssignedTo" /> <xsl:variable name="OriginallyAssignedTo" select="@OriginallyAssignedTo" /> <xsl:variable name="TaskDelegated" select=substring-before(substring-after($CurrentlyAssignedTo, 'userdisp.aspx?ID='), '"') != substring-before(substring-after($OriginallyAssignedTo, 'userdisp.aspx?ID='), '"')" />
The variable $TaskDelegated will be false if the two person fields are the same and true if they are different. Comparison is being made based on the ID parameter which is used in the /_layouts/userdisp.aspx page.
So you could show the task’s original owner if it differs from the current owner like this:
<xsl:value-of select="@AssignedTo" disable-output-escaping="yes"/> <xsl:if test="$TaskDelegated"> (on behalf of <xsl:value-of select="@OriginallyAssignedTo" disable-output-escaping="yes" />) </xsl:if>