Friday, July 4, 2008

Display Link to user via XSL Template: User Field Type similar to ddwrt:UserLookup

<xsl:template name="OuterTemplate.GetUserItem">
<xsl:param name="UserValue"/>
<xsl:param name="UserPart"/>
<xsl:choose>

<xsl:when test="string-length(normalize-space($UserValue)) = 0">
<xsl:value-of select="string('')"/>
</xsl:when>

<xsl:otherwise>
<xsl:choose>
<xsl:when test="$UserPart='Name'">
<xsl:value-of select="substring-after($UserValue,'#')"/>
</xsl:when>

<xsl:when test="$UserPart='UserID'">
<xsl:value-of select="substring-before($UserValue,';#')"/>
</xsl:when>

<xsl:when test="$UserPart='DisplayName'">
<xsl:value-of select="concat(substring-after(substring-after($UserValue,'#'),', '),' ',substring-before(substring-after($UserValue,'#'),', '))" />
</xsl:when>

<xsl:when test="$UserPart='UserURL'">
<xsl:value-of select="concat('/_layouts/userdisp.aspx?ID=',substring-before($UserValue,';#'))" />
</xsl:when>

<xsl:otherwise>
<xsl:value-of select="$UserValue" />
</xsl:otherwise>
</xsl:choose></xsl:otherwise>
</xsl:choose>
</xsl:template>

How to use: (@ReportOwner will be formated as [ID;#Last, First])

<xsl:template name="ByTheme" match="Row[@Style='ByTheme']" mode="itemstyle">

<xsl:variable name="Owner">
<xsl:call-template name="OuterTemplate.GetUserItem">
<xsl:with-param name="UserValue" select="@ReportOwner"/>
<xsl:with-param name="UserPart" select="'DisplayName'"/>
</xsl:call-template>

</xsl:variable>
       
<xsl:variable name="OwnerInfoURL">
<xsl:call-template name="OuterTemplate.GetUserItem">
<xsl:with-param name="UserValue" select="@ReportOwner"/>
<xsl:with-param name="UserPart" select="'UserURL'"/>      
</xsl:call-template>
</xsl:variable>

<a href="{$OwnerInfoURL}" target="_blank"><xsl:value-of select="$Owner"/></a>
</xsl:template>

1 comment:

dan rogy said...

My current project requires ability to display choice column value via color or image associated with a choice

But Sharepoint standard packaged misses that control

I am looking for available solutions on market

I came across

http://sharepointfields.com


Does anybody has experiece using it?