Compare two SharePoint person fields in XSLT using SharePoint Designer

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" />)

Get file extention in XSLT

When working with data view web parts or data form web parts in SharePoint, you might want to use some conditional formatting or branching logic, based on the file extention of your SharePoint item.

This xsl template returns the file extention from an URL:

<!-- Determine File Extention template -->
<xsl:template name="get-file-extension">
    <xsl:param name="path"/>
        <xsl:when test="contains($path, '/')">
            <xsl:call-template name="get-file-extension">
                <xsl:with-param name="path" select="substring-after($path, '/')"/>
        <xsl:when test="contains($path, '.')">
            <xsl:call-template name="get-file-extension">
                <xsl:with-param name="path" select="substring-after($path, '.')"/>
            <xsl:value-of select="$path"/>

It runs recursively through the parameter “path” and returns the extention.

You can call and use it like this:

<xsl:variable name="extension">
	<xsl:call-template name="get-file-extension">
		<xsl:with-param name="path" select="@yourcolumnname" />
<!-- example use in branching logic -->
	<xsl:when test="$extension = 'pdf'">
		<!-- add your logic -->