SharePoint 2010: How to pass Web Part Properties into xslt style sheet

There are three files that need to be modified in order to pass the web part properties into the xslt item styles sheet

  1. Your web part file, name.webpart
  2. content query main xslt style, ContentQueryMain.xsl
  3. item style xslt style, ItemStyle.xsl
  4. You can have these file in a custom one with different names just need to remember to update your web part file to point the custom files

So we need to do the following in each of the file in order to get the web part property to show in the xslt item style,

For example:

We want to pass the web part url and display a header in the xslt style sheet when the row count is 1, which is the first row

1. In the webpart file, You will need to add/change the web part property ParameterBindings as the following:

<property name=”ParameterBindings” type=”string”>

&lt;ParameterBinding Name=”WebPartTitle” Location=”WPProperty(Title)”/&gt;

</property>

*notes that binding property name WebPartTitle is what we need to use the same in the style sheet

 

2. You need to add a parameter in ContentQueryMain.xsl

<xsl:param name=”WebPartTitle” />

*note: this parameter name needs to be same as what is specified in the web part file

And modify the template OuterTemplate.CallTemplate to pass the param in ItemStyle to something similar as the following:

Let’s say you want to only pass into the style call “News”

Add a choose statement

<xsl:choose>

<xsl:when test=”@Style=’News'”>

<xsl:with-param name=”WPTitle” select=”$WebPartTitle” />

</xsl:when>

</xsl:choose>

*note: WPTitle is the param name you wanted to use in the itemstyle, WebPartTitle is what is passed in from the webpart file

 

3. In the itemstyle you need to do the following to read the value pass in:

Add the following in the front of the style,

<xsl:param name=”wpTitle” />

note: this is what we passed in from the content query main

Then you can display it with the format you want, for example:

<xsl:value-of select=”$wpTitle” />

Advertisements

One thought on “SharePoint 2010: How to pass Web Part Properties into xslt style sheet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s