Sharepoint 2010 XSLT Convert Number to Month in order to sort groups

SharePoint lists are great for documents or simple data. Often data contains a special date, timeline, a date for which it is valid or which is important for the data entry. In the listview it might be cool to have a nice view of those entries which belong to a month or year or both. It would be cool to group items by year and month for example.

One of the requirements for a customer project was exactly this. An external list displays items which should be grouped by month.So i created a column in the bdc model for the month which has a value year month (yyyy MM, e.g. 2013 07). It also works if you are using a calculated column, but i had to do it this way cause i am working with an external list. In this case the listview is looking like this:

month1

But instead of month numbers there should be displayed the month name. If i save the month name into the field the ordering goes wrong cause it orders alphabetically (december and then july) but i want the right order in the month. So i decided to save month number and change the listview rendering. In the end it looks as desired:

month

In the xsl of the listview i changed the display behavior.

At first i created a new xsl template (works like a function) and called it “get-month-name”. It has two parameters the month and the year, cause the output will be put together with “year monthname”.

[sourcecode language=”csharp”]




Januar
Februar
März
April
Mai
Juni
Juli
August
September
Okotber
November
Dezember
error:

[/sourcecode]

In the template where your column for the month will be rendered, you add two variables. You split from the value of the column the values for the year and the values for the month and save it into different variables. That will be used to call your new template which we created earlier.

[sourcecode language=”csharp”]


[/sourcecode]

Now it’s time to call the template where the values should be displayed and transfer the variables as parameters to it.

[sourcecode language=”csharp”]




[/sourcecode]

Keep in mind that we didn’t change the values which are saved – we just changed the display properties or the rendering of the values.

In this post you can see how to expand the normal xslt stylesheet with your custom xslt stylesheet (post). I think i should also post how to make it for external lists. Hope i got some time for it soon.

..:: I LIKE SHAREPOINT ::..

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.

Be the first to comment

Leave a Reply

Your email address will not be published.


*