Blog Archive

SharePoint-courses
Guillermo Bas

How to customize a Content Query Web Part: True, False, XSLT and SharePoint 2010 multi-language support

2011-05-10 18:30:00 by Guillermo Bas

I’ve been customizing some XSLT from the ItemStyle.xsl file for the SolidQ Summit SharePoint site. Well, to be fair my colleague José Quinto (@jquintozamora) did it the last year, and I’m applying some modifications requested for this year’s event.

I encountered a problem when I modified an XSL file just to fix a typo and then It seemed mysteriously stop working. When I deep dive into the bugging XSL code I see this simple piece of code:

<xsl:if test="@DEV = 'True'">
    <div class="SD_Area">Development</div>
</xsl:if>
<xsl:if test="@BI = 'True'">
    <div class="SD_Area">Business Intelligence</div>
</xsl:if>
<xsl:if test="@DBA = 'True'">
    <div class="SD_Area">Database Administration</div>
</xsl:if>

That code was working until that moment (at least that was what I thought).

When I fixed the type I retested the page and It stop working (not showing anything, suddenly all xsl:if conditions resulted false!).

The point was about my Regional Configuration (Spanish). SharePoint detected automatically my browser culture and because of the language packs that were installed in the server SharePoint changed even the 'True' string of the list fields by the equivalent Spanish word 'Verdadero' making fail my XSL code.

So, question is, How can we use the True and False logical values in a way that is independent of the language? The answer is in the XSLT language that offer us a clean solution shaped like a function. If we use true() or false() instead of the equivalent string, we will get the True and False logical values universally (with independence of the language we are using for that web site).

Here is the correct code, that will work with every language:

<xsl:if test="@DEV = true()">
	<div class="SD_Area">Development</div>
</xsl:if>
<xsl:if test="@BI = true()">
	<div class="SD_Area">Business Intelligence</div>
</xsl:if>
<xsl:if test="@DBA = true()">
	<div class="SD_Area">Database Administration</div>
</xsl:if>

And that’s all! I hope that this trick that messed my head for some time could help you!

Comments

No Comments
Leave a Comment
(*) Title:
(*) Name:
Your URL:
(*) Comments:
Follow us on: