Another frequent request I receive is the ability to post a message that the site is under construction or an important announcement needs to be displayed. For the announcements, many of my customers do not want to use the actual SharePoint Announcement list. They just want something that stands out on their home page.

So I usually provide one of two solutions:
    - Scrolling Marquee with no styles
    - Scrolling Marquee with styles

Scrolling Marquee (No Styles)

Well, what I actually mean by 'no styles' is simple HTML code with no need to create XSL templates. Usually this is the easiest way to go. But for some other assignments with more complex needs, I had to recourse to well, a little bit more complex of a solution.

And for the simple, easy to implement solution, this is what I do:
 
1. Add a Content Editor Web Part to the page where you would like to display a marquee

2. Edit and modify the Content Editor web part properties, remove the chrome, make any other changes as desired, give the web part a meaningful name (for example, Marquee), and then select [Apply] followed by [OK]

3. Select Click here to add new content at the Content Editor Web Part

4. Locate the HTML icon within the Markup section of the ribbon, select it, and then select Edit HTML Source

5. Type in or copy and paste the code below in the HTML Source web page dialog

<FONT face="Verdana" color=#ff0000 size=2>
<P align=center>
<MARQUEE scrollDelay=95 width=500 height=16>
<DIV align=left>Note: Replace this sample text with any message applicable to your particular situation.</DIV></MARQUEE></P></FONT>


6. Select [OK] and save the page (and publish if publishing is turned on for your site)

You can change anything that is highlighted in red above, as well as the sample text in blue to suit your own needs.

Note: If SharePoint modifies the code above after you saved and it doesn't render as desired, create a TXT file containing the code above, upload the file to a document library, and reference the file via the Content Editor Web Part.

Scrolling Marquee (With Styles)

In a handful of situations I had to create something a little bit more complex than the simple HTML marquee above. For those cases, I used the following elements:
    - Site Column (Optional)
    - Custom List
    - Styles (CSS)
    - XSL Template
    - Customized Content Query Web Part

Step 1 - Site Column (Optional)

Since I don't like doing things more times than absolutely necessary, for most part I end up creating site columns for columns I know I'm going to be using at more than one list or library. For this particular scenario, I created a site column named DisplayYN (Yes/No checkbox or Choice (Yes/No) column). For this example, we are going to say the DisplayYN column is Boolean (Yes/No checkbox).

Step 2 - Create Alerts Custom List

The next step was to create a custom list to manage the Alerts. The list would contain only a couple of columns:
    - Title (the text for the alert)
    - DisplayYN site column

You may be asking yourself why the custom list and why the DisplayYN flag. In many projects I have to work on there's a business approval process behind the scenes where usually the person who creates the text and items on the list is not necessarily the one who gives the green light to display the alerts on the sites. So these people go through review processes until everybody is happy and then the person responsible for the site or alerts edits the item and selects DisplayYN to 'Yes.'

Step 3 - Create The Necessary Styles (CSS)

I create a custom style definition in my CSS file (the copy I created from the corev4.css file). If you have been following my posts, then you know how I advocate towards making copies of Microsoft's files and leaving their original files alone. So back to that point, the following is an example class I may create:
.myAlert
{
     font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 10pt;
    padding: 3px 3px 3px 3px;
    color: #ffffff;
    font-weight: bold;
    text-align: left;
    background-color: red;
    border: 1px gray solid;
}

Don't forget to check in and publish (if needed) your CSS file for the changes to become visible to those users who have been granted the lowest access levels to the site, as well as registering and referencing your external CSS file on your custom master page, as needed.

Step 4 - Create The Necessary Item Style Templates

In your XSL Style Sheet (the one that I hope you copied from Microsoft's original) I create a template, as follows,

<xsl:template name="Alert" match="Row[@'Alert']" mode="itemstyle">
        <div id="alert" class="myAlert">
         <marquee scrollamount="2" scrolldelay="1"><xsl:value-of select="@Title"/></marquee>
        </div>
</xsl:template>


Some designers also like to include an entry on their Content Query Main to declare the above template. Not everybody follows this rule. Depending on the styles, SharePoint will still render the items on the page, whether you modify the Content Query Main file or not.

Step 5 - Create The Custom Content Query Web Part (CQWP)

I add a CQWP to the home page or page where the alert should display at. I then modify the CQWP to use the custom list as source and I set the filter on DisplayYN equals Yes. That way only those items on the custom alerts list that have been selected to be displayed will display.

For most part, my customers never select more than one item at a time. But they usually want to know which other alerts they had published before. That's when this second solution turns out to be better than the simple HTML shared further above.

Then I export the CQWP to my computer and I open it using a tool like Notepad. I then make the following changes:

<property name="ItemXslLink" >/sites/SiteName/Style Library/XSL Style Sheets/CUSTOMItemStyle.xsl</property>

<property name="MainXslLink" >/sites/SiteName/Style Library/XSL Style Sheets/CUSTOMContentQueryMain.xsl</property>

<property name="Xsl" >&lt;xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime" exclude-result-prefixes="xsl cmswrt x" &gt; &lt;xsl:import href="/Style Library/XSL Style Sheets/Header.xsl" /&gt; &lt;xsl:import href="/Style Library/XSL Style Sheets/CUSTOMItemStyle.xsl" /&gt; &lt;xsl:import href="/Style Library/XSL Style Sheets/CUSTOMContentQueryMain.xsl" /&gt; &lt;/xsl:stylesheet&gt;</property>

I save and then I import the updated CQWP to the page. The last thing is to select my style within the drop-down Presentation list within the CQWP tool pane. And finally, I delete the original CQWP from the page once I make sure the customized one is working as expected.
 
Visit this page to view a list of the Locale IDs (LCID) applied in XSL format statements to select the appropriate one for your particular needs if date, time, currency, or all of the above are not displaying in the desired or needed format on a Data View Web Part. (This also applies to Content Query Web Parts.).
 
Add this snippet of code to the Item Style (Style Sheet) file to render the names of the fields being passed to the Content Query Web Part (CQWP). Note that this code will be temporary. You don't want to leave this in the finished Item Style!

<xsl:template name="RenderFieldsBeingPassed" match="Row['RenderFieldsBeingPassed']" mode="itemstyle">
<xsl:for-each select="@*">
   P:<xsl:value-of select="name()" />
</xsl:for-each>
</xsl:template>

Save the file. Return to the site (in the browser) and refresh the page. Open the Web Part Tool Pane for the CQWP and expand Presentation. Then under Styles change the Item Style to the new custom style (RenderFieldsBeingPassed) in the drop down. Select Apply.

The CQWP will now list out all of the fields that are being passed.
 
When displaying dates using Data View or Content Query Web Parts, you might need to format them to the local standards. In order to do that, you may need to use date format functions. But before you can use those, you may need to add a Microsoft schema that does not come by default on your XSL Style Sheet.

I always recommend creating copies of the original files from Microsoft. So I'm assuming that you have created a copy of the original XSL style sheet and you are going to be working on this copy.

Open your XSL Style Sheet. Before modifications, your style sheet should read as follows:
<xsl:stylesheet
     version="1.0" 
     exclude-result-prefixes="x d xsl msxsl cmswrt"
     xmlns:x="http://www.w3.org/2001/XMLSchema" 
     xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" 
     xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:param name="ItemsHaveStreams">

After modifications it should read as this:
<xsl:stylesheet 
     version="1.0" 
     exclude-result-prefixes="x d xsl msxsl cmswrt"
     xmlns:x="http://www.w3.org/2001/XMLSchema" 
     xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" 
     xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
     xmlns:msxsl="urn:schemas-microsoft-com:xslt"
     xmlns:dt="urn:schemas-microsoft-com:datatypes" 
     xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" >
     <xsl:param name="ItemsHaveStreams">

 
Then insert the format date function in the appropriate line of your style sheet. For example, for today's date:

    <xsl:value-of select="ddwrt:Today()"/>

If you would like to have the date in YYYYMMDD format, you can convert it using the FormatDateTime ddwrt function; for example:

    <xsl:value-of select="ddwrt:FormatDate(string(ddwrt:Today()), 1033, 'yyyyMMdd')"/>

Click here to view a full list of Locale IDs (LCID) that can be used as an aid in setting different formats based on locale.
 

This solution allows adding a 'New!' flag to list items via the use of a special column in a custom list, as well as one line of XSL code.
The first thing I do is I create a Yes/No column in my list (you can also create this column as a Site Column if you think you're going to be using it in more than one list or library). For the example, we're going to call this column 'NewYN.'

(If you prefer, you can use a Choice column with two menu options, 'Yes' and 'No,' instead.)

Then in my custom Style Sheet, I add the following code:
<xsl:if test="(@NewYN = 'True')">
<font size="1" color="#FF0000" ><xsl:value-of select="' ~ NEW!'"/></font>
</xsl:if>
In my example, I'm using the colour red (FF0000). You can change this colour to any colour of your choice. (For an article about Web Color Reference, click here.)

The last step woudl be to modify the Content Query Web Part as appropriate so it can read your style sheets.