2

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 ...
</xsl:if>

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

 <span>
           <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'/>
           </a>
    </span>

And not just “***, Stef”

Alex Angas
  • 5,961
  • 9
  • 49
  • 89
Stef Heyenrath
  • 877
  • 13
  • 26

1 Answers1

1

Solution is very simple.

Don’t do test on 'equals'

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



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

<xsl:if test="contains(@MyField, $UserID)">
    ... things here ...
</xsl:if>
Stef Heyenrath
  • 877
  • 13
  • 26
  • 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 '"' before an after the $UserID to eliminate this problem. – MBSurf Feb 19 '10 at 20:00
  • On my page, $UserId is defined as : And it's represented as 'Lastname, Firstname', so the contains() function will work correct. – Stef Heyenrath Feb 23 '10 at 10:03
  • This is nice. Very simple and easy solution. – jle Nov 08 '12 at 11:47