Monday, 5 September 2011

Using localized strings in XSLT of Summary Link webpart



Hello All,

Discussion Topic:
In my project we have requirement like, we have to display a localized string in Summary Link webpart. String like “See all”, since we have multilingual site we will require localized version of this string. So we decided to get string “See all” string from the resource file in XSLT.
So here we are going to discuss how to get the value from resource files in Summary Link webpart XSLTs.

Description:
SummaryLink webpart is derived from DataFormWebPart webpart as  
                Microsoft.SharePoint.WebPartPages.DataFormWebPart
                  Microsoft.SharePoint.Publishing.WebControls.CmsDataFormWebPart
                    Microsoft.SharePoint.Publishing.WebControls.SummaryLinkWebPart (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.webcontrols.summarylinkwebpart.aspx )

There is <ParameterBindings> property of DataFormWebPart webpart.  This property makes the resource strings available in XSLTs.

Syntax for <ParameterBindings> property in SummaryLinkWebPart definition file is as
<property name="ParameterBindings" type="string" >

&lt;ParameterBinding Name="testparameter" Location="Resource(resourcefilename,resourcestringwhosevalueneedtomakeavailable)" /&gt;

</property>

In above syntax only we need to mention the <ParameterBindings> property in SummaryLinkWebPart definition file.

Now here,
1.       Location specifies the Resource function. SharePoint foundation uses Resource function to get the value of specified resource strings. You will get more details here.
2.       Name is used in XSLT as parameter.
Now once you specified, in XSLT you will get this value as a parameter. I.e. in SummaryLinkMain.xsl file you will get the value from resource file by define it as follows

<xsl:param name=" testparameter" />

Here parameter name is same as specified in webpart definition file, i.e testparameter. Once I define this parameter in XSLT then I can use this value in XSLT as

<xsl:value-of select="$testparameter "/>


Also we can pass this value in ItemStyle.xslt also by using <xsl:with-param> element as

<xsl:apply-templates select="." mode="itemstyle">
       <xsl:with-param name="teste1234" select="$tes123t"></xsl:with-param>
</xsl:apply-templates>


These XSLTs are always having fun to work J Enjoy!

No comments: