SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a custom list there is a column / field defined as “Name (with presence)”.

In my modified aspx page, I want to do an ‘xsl if’ statement to check if the value from this field is the same as the current user.

<xsl:if test="@MyField = $UserID">
    ... code here ...

But the compare fails because the content from the MyField is something like :

           <A HREF="/sites/121579/MySite/_layouts/userdisp.aspx?ID=452">***, Stef</A>
           <img border="0" height="1" width="3" src="/_layouts/images/blank.gif"/>
           <a href='javascript:' onclick='IMNImageOnClick();return false;' class='ms-imnlink'>
                  <img name='imnmark' title='' border='0' height='12' width='12' src='/_layouts/images/blank.gif' alt='No presence information' sip='stef.***@***.com' id='imn_998,type=smtp'/>

And not just “***, Stef”

share|improve this question
up vote 1 down vote accepted

Solution is very simple.

Don’t do test on 'equals'

<xsl:if test="@MyField = $UserID">
    ... things here ...

But a test on 'contains' (Just check if the field ‘MyField’ contains the value from $UserID)

<xsl:if test="contains(@MyField, $UserID)">
    ... things here ...
share|improve this answer
You could get a false positive this way. Since the UserID contained in the field is an integer, the first user in the UserInfo list will pass this test on anyone with a 1 in the ID. You could include the 'userdisp.aspx?ID=' and '&quot;' before an after the $UserID to eliminate this problem. – MBSurf Feb 19 '10 at 20:00
On my page, $UserId is defined as : <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/> And it's represented as 'Lastname, Firstname', so the contains() function will work correct. – Stef Feb 23 '10 at 10:03
This is nice. Very simple and easy solution. – jle Nov 8 '12 at 11:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.