Data View Conditional Formatting

One of the things XSLT makes really easy is "conditional formatting", i.e. having parts of your view appear differently depending on some data condition.

Quick example: let's say you have a view of a "Product Sales" list, and you want to show a flag icon beside any product that's sold more than 500 units. The first step is to add the flag image into the view, which will cause it to show up for every row:

Next, right click the flag image, and choose "Conditional Formatting". This will bring up the Conditional Formatting task pane. You can use this task pane to create new conditional formattings as well as manage existing ones.

Now click the "Create" button and choose "Show Content" - this will bring up the "Condition Criteria" dialog, where you will define the condition under which the content should be shown. For this scenario, we want to show the flag icon when "Units Sold > 500":

Press ok in the "Condition Criteria" dialog and you are done! You should now have a view where the flag icon only shows for products with greater than 500 units sold.

There are tons of cool ways to use this ability to conditionally show&hide content. One I use often is the "red light/green light" scenario - I put both a red light and green light icon in my, and define conditional formatting for both so that each row shows either a red light or a green light, giving a very quick very indication of whether an item is tracking to plan or not. Next up, I'll show how you can use conditional formatting to change the actual formatting of your view.