3 ways to localize SharePoint XSLT

Source: Internet
Author: User
Tags xsl xslt

SharePoint often provides several ways to accomplish the same task. And more often than not, the majority of the approaches are far from being valid tive.

SharePoint often provides several ways to accomplish the same task. And more often than not, the majority of the approaches are far from being valid tive.

Today I'll describe the XSLT localization approaches and advantages/disadvantages of each of them.

But first, why does that kind of task deserve our attention? That's because of a bunch of awesome webparts, all derived from basexsltdatawebpart-You all know them very well, they are: dataviewwebpart (dvwp), dataformwebpart (dfwp ), extends tlistviewwebpart (XLV), extends tlistformwebpart (XLF), and contentbyquerywebpart (cqwp ).

So, sooner or later, if you have multilingual portals, you will face the necessity of the XSLT localization. That is inevitable.

App_globalresources

Before we start, the first thing you have to remember is that your resources shoshould be placed inApp_globalresourcesFolder under the IIS web application directory. For details on how to do this, you can refer to the article did you know: Provisioning appglobalresources in SharePoint 2010 by waldek mastykarz.

Copying your resx files14/ResourcesFolder will not work for XSLT! In the end, you canReinvent a bicycleEnd up with a constant parameterbinding-thus, "on Fly" SharePoint 2010 localization will be broken.

1. parameterbinding

The first approach concerns parameterbindings property.

1
<Parameterbinding Name="Parametername" Location="Resource (resourcefile, resourcename )" />

Parameter Bindings are passed to XSLT, so you can grab them with XSL: Param, providing the sameParametername:

1
<XSL: Param Name="Parametername" />

This way is decent, but not very convenient: You will have to add a parameterbinding each time you will need a resource. After 10-20 resources, trust me, it will become very irritating!

And another peculiar detail: there are no spaces allowedResourcefileAndResourcename!! Thus, a single typo cocould bring you to a "Desperate bug" struggle

2. XPath expressions

The most tasty way, however, is what I call "magic ". I dislike it a bit, because of the notorious pixel hunting, "hidden URLs", etc. -But those all are the same kind of things, actually.

The trick is that using peculiar XPath queries, you will, all of the sudden :), get a localized value. The syntax is as follows:

1
<XSL: value- Select="/Dsqueryresponse/rows/@ resource. resourcefile. resourcename" />

And I can't resist mentioning, that you can't use resx files with dot in their names. since in our main project at work all the resource files use "product. module. resx "naming format, we are overboard with that approach # fail

But, these two ways are already described well in the XSLT Parameter Bindings article on msdn, so you might ask, hey guy, and there are your five cents !?

And yes, here it comes!

3. server controls

It is no secret, that you can use server controls in SharePoint XSLT. even your own controls, by the way, as it was explained in a recent nothingbutsharepoint post custom controls in XSLT, written by Pranav Sharma. and if you're familiar with ASP. net localization syntax, you may have had the same idea.

The idea cocould then be converted into the following XSLT template:

01
<XSL: Template Name="Localize">

02
<XSL: Param Name="Name" />

03
<XSL: Choose>

04
<XSL: When Test="Starts-with ($ name, '$ resources :')">

05
<SharePoint: encodedliteral Runat="Server" TEXT = "<% {$ name }%>"/>

06
</XSL: When>

07
<XSL: otherwise>

08
<XSL: value- Select="$ Name" />

09
</XSL: otherwise>

10
</XSL: Choose>

11
</XSL: Template>

Despite a slight awkwardness, this is a fairly powerful approach, because you can use standard "$ resources: file, name" syntax in some parameters or even in field values, and this will give us some extra capabilities. for a real example, Sharepoint itself uses this approach to localize xmldefinition XAML controls of xsltlistformwebpart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.