Monday, May 14, 2012

Add Lync Presence to SharePoint List column with XSL Stylesheet

If you want display Lync link with your contact list.
  1. Add column to the list Single line of text will call Presence.
  2. Edit Contact List Web Part Set XSL Link Property with new xsl.
  3. Create a XSL file with a style sheet, this style will add presence based on the Email field in the Contact list.
    <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">
     <xsl:include href="/_layouts/xsl/main.xsl"/>
     <xsl:include href="/_layouts/xsl/internal.xsl"/>
     <xsl:template name="FieldRef_Text_body.Presence" match="FieldRef[@Name='Presence']" mode="Text_body">
      <xsl:param name="thisNode" select="."/>
      <xsl:variable name="etternavn">
       <xsl:value-of select="$thisNode/@Title" />
      </xsl:variable>
      <xsl:variable name="fornavn">
       <xsl:value-of select="$thisNode/@FirstName" />
      </xsl:variable>
      <xsl:variable name="fulltNavn">
       <xsl:value-of select="concat($fornavn,' ',$etternavn)" />
      </xsl:variable>
      <xsl:variable name="itemID">
       <xsl:value-of select="$thisNode/@ID" />
      </xsl:variable>
     
      <xsl:variable name="sipAfter">
       <xsl:value-of select="substring-after($thisNode/@Email,':')" />
      </xsl:variable>
      <xsl:variable name="sip">
       <xsl:value-of select="substring-before($sipAfter,'"')" />
      </xsl:variable>
     
       <div id="PresenceLink_{$itemID}"><span class="ms-imnSpan"><img border='0' height='12' src='/_layouts/images/imnhdr.gif' onload="IMNRC('{$sip}')" ShowOfflinePawn='1' style='padding-right: 3px;' id="PresencePawn_{$itemID}" alt='pawn' /> <a href='' id="ProfileLink_{$itemID}"><xsl:value-of select="$fulltNavn" /></a></span></div>
     </xsl:template>
    </xsl:stylesheet>

1 comment:

Chris said...

Can the description of what to do be better explained here. I dont understand what you mean about xsl and creating a stylesheet. I cant see how this is supossed to work.