Posted by Elio Struyf on 11/07/2012.
This post explains the second demo that I showed at my SharePoint Saturday Belgium presentation.
The second demo was about XSLT statements. XSLT statements are used to put a conditional test against the data source you are using.
If my value is equal to "deferred" than show or do this.
In my demo I used this to change the background color or the table row based on the task status value:
- Completed: Green;
- Deferred: Red;
- In Progress: Gray.
The best way to start with XSLT statements is with creating a new list view and adding conditional formatting to it.
Open your site in SharePoint Designer and go to List and Libraries and click on your task list.
On the Views section click the New button, and give your list view a meaningful name.
Click OK, and open the newly created view.
Select the whole row, do a right-click, and click on Conditional Formatting.
At the right side the Conditional Formatting panel will open. Click on Create -> Apply formatting.
Set your condition as follows:
Click Set Style, and in the background section add #FFCFD1 as the background-color value.
If you switch to the code view and do a search for Deferred you should see the following code:
|<xsl:if test="normalize-space($thisNode/@Status) = 'Deferred'" ddwrt:cf_explicit="1">background-color: #FFCFD1;</xsl:if>|
To add the other background colors to the rows, you can add the following lines to the code:
|<xsl:if test="@Status = 'Completed'">background-color: #DFFFDF;</xsl:if>|
<xsl:if test="@Status = 'In Progress'">background-color: #DFDFDF;</xsl:if>
When you are using a lot of IF statements for the same column, you can use the choose statement.
In the choose statement you can express multiple tests to your column.
The IF statements can be easily changed to a CHOOSE statement. It will look like this:
<xsl:when test="@Status='In Progress'">
Notice the otherwise element, this will be used when none of your tests met the condition.
In part 3 I will explain you how to re-create the Twitter web part that I created during my presentation.