SharePoint – Return a Lookup Column Value as Text

December 21, 2013

The most annoying thing in SharePoint is that if you have a lookup column value in a list. And you want to retrieve this value as a text it will not work OOTB.

Let’s see here what I mean :

When you want to show a lookup column called CRM_Account using the standard “xsl” syntax.

           <xsl:variable name=”ID”>
            <xsl:call-template name=”ResolveId”>
                <xsl:with-param name=”thisNode” select=”$thisNode” />
    <xsl:value-of select=”$thisNode/@CRM_Account”/>

You get this onclick=”OpenPopUpPage Hyperlink result, instead of the text of the lookup column.


When you add this xsl syntax you will get the correct text representative of the lookup column value. 

<xsl:value-of select=”substring-before(substring-after($thisNode/@*[name()=current()/@Name],’&gt;’), ‘&lt;’)” disable-output-escaping=”yes”/>

How to set a variable and set a value to retrieve in a new column.

Set a variable called CRM_ID and put the CRM_Account_ID in there, last is to retrieve it.

<xsl:variable name=”CRM_ID”><xsl:value-of select=”$thisNode/@CRM_Account_ID”/></xsl:variable>

<xsl:value-of select=”$CRM_ID”/>

Enjoy !