XSLT Parameter Bindings

XSLT Parameter Bindings

SharePoint 2010

Last modified: October 21, 2010

Applies to: SharePoint Foundation 2010

XSLT style sheets in Microsoft SharePoint Foundation 2010 reuse the existing global resource strings that are traditionally used in Collaborative Application Markup Language (CAML) views, which you can use in custom XSLT. For example, the main.xsl file, which explicitly declares parameters that are available for use in XSLT, includes the following Boolean parameter that indicates whether the current list is a document library: <xsl:param name="IsDocLib"/>. If you import main.xsl into a style sheet, you can return the value of this parameter by prepending a dollar sign ($) to the name, as follows: <xsl:if test="$IsDocLib">.

SharePoint Foundation also uses parameter bindings to make resources available to XSLT transforms. To define a resource for use within XSLT, you can define the resource in a .resx file, bind the resource to a view by declaring it in the <ParameterBindings> section of the list’s Schema.xml file, and then consume the resource in your custom XSLT. You can also programmatically add a parameter binding through the object model.

For information about how to use parameters to bind resources to views, see XSLT Parameter Bindings.

You can make resource strings available to XSLT transforms in one of two ways:

  • As style sheet parameters (<xsl:param>) that are retrieved through <ParameterBinding> tags in the Web Part (see ParameterBinding).

  • As XPath expressions that are used in <xsl:value-of> tags.

The ParameterBinding element includes a Location attribute that specifies resource types. The syntax for this element is similar to the ASP.NET resource binding expression syntax:

<ParameterBinding Name=" parameterName " Location="Resource( resourceFile , resourceName )" />

The Location value is expressed as a function that has the following parameters:




The base name of a SharePoint Foundation resource file, without the extension. For example: wss, or core.


The name of the resource string. For example: string1.

In addition to specifying a localized resource in a .resx file, you can use the Location attribute to specify values for contexts that are listed in the following table.



Query strings

<ParameterBinding Name="SelectedID" Location="QueryString(SelectedID)"/>Corresponding code in XSL: <xsl:param name="SelectedID"/>


<ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>

Server variables


Web Part properties


Control IDs


You can use the server object model to add a parameter binding to the collection of bindings for an XsltListViewWebPart object through the ParameterBindings property of the Web Part, or through the ParameterBindings property of the SPView object that is associated with the Web Part. But you can also declaratively add a <ParameterBinding> tag to the <ParameterBindings> section of a View element in a list’s Schema.xml file to declare a parameter binding for use in XSLT. For example, the following tag makes a string available for display in document library list views when there are no items:

<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noitemsinview_doclibrary)" />

In the example, NoAnnouncements is the name of the resource for use in XSLT, wss is the name of the file that contains the resource minus the file name extension, and noitemsinview_doclibrary is the name of the resource as represented in the resource file.

After the <ParameterBinding> tag is added to the <ParameterBindings> collection on the Web Part, it becomes available to the XSLT style sheet by defining a top-level <xsl:param> tag of the same name:

<xsl:param name="NoAnnouncements"/>

You can then consume the resource by using an XPath expression anywhere in the style sheet, as in the following:<xsl:value-of select="$NoAnnouncements" />

To retrieve resources, SharePoint Foundation uses a special XPath syntax that is interpreted by the XPathNavigator object that is used by the XsltListViewWebPart object when the transform runs. The syntax is specified as follows, where the resourceFile parameter and the resourceName parameter have the same meaning as described previously.

<xsl:value-of select="@Resources. resfile . resname " />

The following example retrieves the same resource as the previous example:

<xsl:value-of select="@Resources.wss.noitemsinview_doclibrary" />

Note Note

Because a SharePoint Foundation internal field name cannot contain a dot (".") character, a resource expression cannot be confused with a normal field reference.

© 2016 Microsoft