I have created a custom field type that renders the input as an html link. The xsl transform that creates the link tag should prepend the user input with a base url from an xsl parameter. I want this prefix to be passed in when the transform is applied so it isn’t hardcoded in the file and can be changed by the user. I believe it can be done by creating a custom web part and then adding this web part to all the pages where you want this to appear (e.g. helpmeonsharepoint). I would like to pass in a parameter in general regardless of which web part the xslt transform is applied to.

I can get this working in a console app which I achieved by following these instructions however I can’t transfer this into SharePoint. I tried simply passing in a c# object shown in the following code snippet:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"

<xsl:template name="fldTypes" … >        
            <xsl:attribute name="href">
                <xsl:value-of select="helper:ConcatUrl($DocId)"/>
            <xsl:value-of select="$DocId"/>

When the transform gets applied however I keep getting the following error: “Cannot find the script or external object that implements prefix ‘SampleApplication.ClassName’”. Comparing this to the console app it seems that I am missing the part where I pass in the object by modifying the Xslt Argument List via the AddExtensionObject Method. However, I’m not sure where this code should go if I don’t use a web part. Is this heading in the right direction?


Adding XSLT extension object

The following steps are required:

It means, in order to pass XSLT extension object we need to subclass XSL based web part and override ModifyXsltArgumentList the as shown below:

    protected override void ModifyXsltArgumentList(ArgumentClassWrapper argList)

      WebPartRuntime webPartRuntime = new WebPartRuntime();
      argList.AddExtensionObject("http://schemas.contoso.com/webparts/runtime", (object) webPartRuntime);


For XSLT based web parts using ParameterBinding property allows to specify parameters that are available for use in XSLT. For more details see XSLT Parameter Bindings

In your scenario it means that it is doable to pass for OOTB XSL based web parts

  • End users specify custom parameter (Prefix in your case) via ParameterBinding web part property, for example <ParameterBinding Name="BaseUrl" DefaultValue="SomeValue" />

  • XSLT template should be implemented for generating links (C# ConcatUrl analogue in your case)

In that case there is no need to create custom web part.

Figure 1. How to specify ParameterBindings via tool part (ex. Core Results web part)

Core Results web part

  • Thanks Vadim. Some clarification if you will. I interpret the statement "need to subclass XSL based web part" as implying that the subclassed web part will then need to be added where it is used. Is this correct? Also could you clarify what you mean by 'Prefix'? Is that referring to my 'SampleApplication.ClassName' class? – Sebastian Carroll Jul 25 '13 at 1:48
  • Sebastian, regarding subclassed web part, that is correct. In case of "Prefix", for requirement "The xsl transform that creates the link tag should prepend the user input with a base url from an xsl parameter", my suggestion is to pass this parameter to XSL via ParameterBindings web part property - all XSLT based web parts (DataFormWebPart) include this property. After that XSLT template should be implemented for generating links ("helper:ConcatUrl($DocId)" C# analogue in your case) – Vadim Gremyachev Jul 25 '13 at 7:16
  • Thanks again. I haven't yet got it working but I've made a great deal of progress. – Sebastian Carroll Jul 26 '13 at 0:18
  • With regards to this statement, "End users specify custom parameter via ParameterBinding web part property", How would the end user specify this parameter? – Sebastian Carroll Jul 26 '13 at 5:54
  • Sebastian, for specifying Parameter Binding values is intended Parameters Editor, please check my updated answer – Vadim Gremyachev Jul 26 '13 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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