SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

I have two lists Client and Project, each Client has from 0 to N Project stocked in his SPLookupField where multi values are allowed. And I created a new computed Column in the Client List where it shows a link to the page of all of my Projects only when he has indeed project otherwise it won't show the link. Here's the field in the schema of the Client List:

<Field ID="{BD65ECB7-1BFE-4154-844E-3FDC9A760830}" Name="ProjectsLink" StaticName="Projects" ShowInNewForm="FALSE" ShowInEditForm="FALSE" ShowInDisplayForm="FALSE"  Sortable="FALSE" Filterable="FALSE"  Type="Computed"  DisplayName="Projects" ClassInfo="Icon" AuthoringInfo="$Resources:core,linked_to_item;" >
      <HTML><![CDATA[<a href="]]></HTML>
      <URL Cmd="DISPLAY" />
      <HTML><![CDATA[" onclick="GoToLink(this);return false;" target="_self">]]></HTML>
      <HTML><![CDATA[<img  Width="25px" Height="20px" border="0" alt="]]></HTML>
      <Field Name="FileLeafRef"  />
      <HTML><![CDATA[" src="/_layouts/DISPLAY.png">]]></HTML>

so in order to add this Field in my List I have created an XSLT file but I didn't know how to indicate my second condition because it depends on a method in my cs file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:x=""
            version="1.0" exclude-result-prefixes="xsl msxsl ddwrt"
            xmlns:ddwrt2="urn:frontpage:internal" ddwrt:oob="true">
  <xsl:template name="FieldRef_ProjectsLink_body" ddwrt:dvt_mode="body" match ="FieldRef[@Name='ProjectsLink']" mode="Computed_body">
<xsl:param name="thisNode" select="."/>
<xsl:param name="ShowAccessibleIcon" select="0"/>
<xsl:param name="folderUrlAdditionalQueryString" select="''"/>
<xsl:variable name="ID">
  <xsl:call-template name="ResolveId">
    <xsl:with-param name="thisNode" select ="$thisNode"/>
  <xsl:when test="$XmlDefinition/List/@TemplateType != 301"> <!--and Condition2-->
    <a onfocus="OnLink(this)" href="{$FORM_DISPLAY}&amp;ID={$ID}&amp;ContentTypeID={$thisNode/@ContentTypeId}" onclick="EditLink2(this,{$ViewCounter});return false;" target="_self">
      Details -
    <a onfocus="OnLink(this)" href="/_LAYOUTS/Projects.aspx?ID={$ID}" onclick="EditLink2(this,{$ViewCounter});return false;" target="_self">
      <a onfocus="OnLink(this)" href="{$FORM_DISPLAY}&amp;ID={$ID}" onclick="GoToLink(this);return false;" target="_self">
        Details -

and in my ClientManagement.cs file I have this function that gives me the number of all client's projects :

public static int getProjectsCount(int pClientID)
         SPSite mysite = new SPSite(SPContext.Current.Web.Site.Url);
         SPWeb myweb = mysite.OpenWeb();
         SPListItem myContact = myweb.Lists["Client"].Items.GetItemById(pClientID);

         SPFieldLookupValueCollection fieldValues = myContact["Projects"] as SPFieldLookupValueCollection;
         return fieldValues.Count;

So my question is how to call this function my XSL file to use it as a condition??

share|improve this question
Did you ever get this figured out? If so, please accept an answer below or provide the answer that worked for you. – Steve Lineberry Mar 12 '13 at 18:24
up vote 1 down vote accepted

When you execute the transform, one of the required properties is the xslArgs. When creating this xslargs object you can assign it an extension object which you can then call methods within that object from your XSLT.

C# Sample Code

XsltArgumentList xslArgs = new XsltArgumentList();
ClientManagement cs = new ClientManagement();  //Your custom code
xslArgs.AddExtensionObject("urn:ClientManagement", cs);

XslCompiledTransform transform = new XslCompiledTransform();

using (StringWriter writer = new StringWriter())
    transform.Transform(content, xslArgs, writer);
    return writer.ToString();

XSLT sample code

<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:myObj="urn:ClientManagement">
<xsl:value-of select="myObj:getProjectsCount($pClientID)"/>  
share|improve this answer

Could you embed the c# function in your XSL?

share|improve this answer
according to this blog no!… – Glolita Mar 6 '13 at 15:46
Good call -> I didn't see that blog & didn't realize that limitation. Hopefully the extension object that Steve Lineberry has proposed will work for you! – Jason Rastovski Mar 6 '13 at 16:09
@Glolita, that blog you posted seems to be talking about the same thing I am in my answer. – Steve Lineberry Mar 6 '13 at 16:10

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.